1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
12 "git.curoverse.com/arvados.git/lib/cmd"
13 "git.curoverse.com/arvados.git/sdk/go/arvados"
14 "github.com/ghodss/yaml"
17 var Get cmd.Handler = getCmd{}
21 func (getCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
25 fmt.Fprintf(stderr, "%s\n", err)
29 flags, opts := LegacyFlagSet()
30 flags.SetOutput(stderr)
31 err = flags.Parse(args)
35 if len(flags.Args()) != 1 {
36 fmt.Fprintf(stderr, "usage of %s:\n", prog)
45 client := arvados.NewClientFromEnv()
46 path, err := client.PathForUUID("show", id)
51 var obj map[string]interface{}
52 err = client.RequestAndDecode(&obj, "GET", path, nil, nil)
54 err = fmt.Errorf("GET %s: %s", path, err)
57 if opts.Format == "yaml" {
59 buf, err = yaml.Marshal(obj)
61 _, err = stdout.Write(buf)
63 } else if opts.Format == "uuid" {
64 fmt.Fprintln(stdout, obj["uuid"])
66 enc := json.NewEncoder(stdout)
67 enc.SetIndent("", " ")
71 err = fmt.Errorf("encoding: %s", err)