cli

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2016 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package cli processes default environment values, log handling, version number and other common code blocks used to implement cli tools.

@author R. S. Doiel, <rsdoiel@gmail.com> copyright (c) 2015 all rights reserved. Released under the Simplified BSD License. See: http://opensource.org/licenses/BSD-2-Clause

Index

Constants

This section is empty.

Variables

View Source
var CommandName = func(s string) string {
	return filepath.Base(s)
}

CommandName takes a path and returns the basename of the command.

View Source
var Usage = func(exit_code int, body string, msg string) {
	var fh = os.Stderr
	if exit_code == 0 {
		fh = os.Stdout
	}
	fmt.Fprintf(fh, `%s
 USAGE %s [options]
 %s
 OPTIONS

`, msg, CommandName(os.Args[0]), body)

	flag.VisitAll(func(f *flag.Flag) {
		fmt.Fprintf(fh, "\t-%s\t(defaults to %s) %s\n", f.Name, f.DefValue, f.Usage)
	})

	fmt.Fprintf(fh, `

 copyright (c) 2014 all rights reserved.
 Released under the Simplified BSD License
 See: http://opensource.org/licenses/bsd-license.php

`)
	os.Exit(exit_code)
}

Usage info for the command

View Source
var Version = func() {
	fmt.Printf("%s version %s\n", os.Args[0], revision)
	os.Exit(0)
}

Version info for the command

Functions

func DefaultEnvBool

func DefaultEnvBool(environmentVar string, defaultValue bool) bool

DefaultEnvBool returns the environment boolean value or default if not set.

func DefaultEnvInt

func DefaultEnvInt(environmentVar string, defaultValue int) int

DefaultEnvInt returns the environment value of the string or the default if not set.

func DefaultEnvString

func DefaultEnvString(environmentVar string, defaultValue string) string

DefaultEnvString returns the environment value of the string or the default if not set.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL