arvados: git.arvados.org/arvados.git/lib/cmd Index | Files

package cmd

import "git.arvados.org/arvados.git/lib/cmd"

package cmd helps define reusable functions that can be exposed as [subcommands of] command line programs.

Index

Package Files

cmd.go

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.

func SubcommandToFront Uses

func SubcommandToFront(args []string, flagset FlagSet) []string

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.

type FlagSet Uses

type FlagSet interface {
    Init(string, flag.ErrorHandling)
    Args() []string
    NArg() int
    Parse([]string) error
    SetOutput(io.Writer)
    PrintDefaults()
}

type Handler Uses

type Handler interface {
    RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int
}

type HandlerFunc Uses

type HandlerFunc func(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int

func (HandlerFunc) RunCommand Uses

func (f HandlerFunc) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int

type Multi Uses

type Multi map[string]Handler

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"}))

...prints "baz" and exits 2.

func (Multi) RunCommand Uses

func (m Multi) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int

func (Multi) Usage Uses

func (m Multi) Usage(stderr io.Writer)

Package cmd imports 9 packages (graph) and is imported by 28 packages. Updated 2020-02-23. Refresh now. Tools for package owners.