Documentation ¶
Overview ¶
Package cmd helps define reusable functions that can be exposed as [subcommands of] command line programs.
Index ¶
Constants ¶
const EXIT_INVALIDARGUMENT = 2
Variables ¶
var Version versionCommand
Version is a Handler that prints the package version (set at build time using -ldflags) and Go runtime version to stdout, and returns 0.
Functions ¶
func ParseFlags ¶
func ParseFlags(f FlagSet, prog string, args []string, positional string, stderr io.Writer) (ok bool, exitCode int)
ParseFlags calls f.Parse(args) and prints appropriate error/help messages to stderr.
The positional argument is "" if no positional arguments are accepted, otherwise a string to print with the usage message, "Usage: {prog} [options] {positional}".
The first return value, ok, is true if the program should continue running normally, or false if it should exit now.
If ok is false, the second return value is an appropriate exit code: 0 if "-help" was given, 2 if there was a usage error.
func SubcommandToFront ¶
SubcommandToFront silently parses args using flagset, and returns a copy of args with the first non-flag argument moved to the front. If parsing fails or consumes all of args, args is returned unchanged.
SubcommandToFront invokes methods on flagset that have side effects, including Parse. In typical usage, flagset will not used for anything else after being passed to SubcommandToFront.
Types ¶
type FlagSet ¶
type Handler ¶
type HandlerFunc ¶
type Multi ¶
Multi is a Handler that looks up its first argument in a map (after stripping any "arvados-" or "crunch-" prefix), and invokes the resulting Handler with the remaining args.
Example:
os.Exit(Multi(map[string]Handler{ "foobar": HandlerFunc(func(prog string, args []string) int { fmt.Println(args[0]) return 2 }), })("/usr/bin/multi", []string{"foobar", "baz"}, os.Stdin, os.Stdout, os.Stderr))
...prints "baz" and exits 2.