X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6def96daca7a5ec60dc067c04864bc58bd4aaf5c..2efd88cf64130bb0ebb0549d30053b85baaae2f9:/lib/cli/get.go diff --git a/lib/cli/get.go b/lib/cli/get.go index a7adfb65b6..9625214e22 100644 --- a/lib/cli/get.go +++ b/lib/cli/get.go @@ -6,15 +6,19 @@ package cli import ( "encoding/json" - "flag" "fmt" "io" - "git.curoverse.com/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/lib/cmd" + "git.arvados.org/arvados.git/sdk/go/arvados" "github.com/ghodss/yaml" ) -func Get(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int { +var Get cmd.Handler = getCmd{} + +type getCmd struct{} + +func (getCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int { var err error defer func() { if err != nil { @@ -22,25 +26,19 @@ func Get(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) } }() - flags := flag.NewFlagSet(prog, flag.ContinueOnError) - format := flags.String("format", "json", "output format (json, yaml, or uuid)") - flags.StringVar(format, "f", "json", "output format (json, yaml, or uuid)") - short := flags.Bool("short", false, "equivalent to --format=uuid") - flags.BoolVar(short, "s", false, "equivalent to --format=uuid") - flags.Bool("dry-run", false, "dry run (ignored, for compatibility)") - flags.Bool("n", false, "dry run (ignored, for compatibility)") - flags.Bool("verbose", false, "verbose (ignored, for compatibility)") - flags.Bool("v", false, "verbose (ignored, for compatibility)") + flags, opts := LegacyFlagSet() + flags.SetOutput(stderr) err = flags.Parse(args) if err != nil { return 2 } if len(flags.Args()) != 1 { - flags.Usage() + fmt.Fprintf(stderr, "usage of %s:\n", prog) + flags.PrintDefaults() return 2 } - if *short { - *format = "uuid" + if opts.Short { + opts.Format = "uuid" } id := flags.Args()[0] @@ -56,13 +54,13 @@ func Get(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) err = fmt.Errorf("GET %s: %s", path, err) return 1 } - if *format == "yaml" { + if opts.Format == "yaml" { var buf []byte buf, err = yaml.Marshal(obj) if err == nil { _, err = stdout.Write(buf) } - } else if *format == "uuid" { + } else if opts.Format == "uuid" { fmt.Fprintln(stdout, obj["uuid"]) } else { enc := json.NewEncoder(stdout)