1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
15 "git.arvados.org/arvados.git/lib/cmd"
19 Create = rubyArvCmd{"create"}
20 Edit = rubyArvCmd{"edit"}
22 Copy = externalCmd{"arv-copy"}
23 Tag = externalCmd{"arv-tag"}
24 Ws = externalCmd{"arv-ws"}
26 Keep = cmd.Multi(map[string]cmd.Handler{
27 "get": externalCmd{"arv-get"},
28 "put": externalCmd{"arv-put"},
29 "ls": externalCmd{"arv-ls"},
30 "normalize": externalCmd{"arv-normalize"},
31 "docker": externalCmd{"arv-keepdocker"},
33 // user, group, container, specimen, etc.
34 APICall = apiCallCmd{}
37 // When using the ruby "arv" command, flags must come before the
38 // subcommand: "arv --format=yaml get foo" works, but "arv get
39 // --format=yaml foo" does not work.
40 func legacyFlagsToFront(subcommand string, argsin []string) (argsout []string) {
41 flags, _ := LegacyFlagSet()
42 flags.SetOutput(ioutil.Discard)
45 argsout = append(argsout, argsin[:len(argsin)-narg]...)
46 argsout = append(argsout, subcommand)
47 argsout = append(argsout, argsin[len(argsin)-narg:]...)
51 type apiCallCmd struct{}
53 func (cmd apiCallCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
54 split := strings.Split(prog, " ")
56 fmt.Fprintf(stderr, "internal error: no api model in %q\n", prog)
59 model := split[len(split)-1]
60 return externalCmd{"arv"}.RunCommand("arv", legacyFlagsToFront(model, args), stdin, stdout, stderr)
63 type rubyArvCmd struct {
67 func (rc rubyArvCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
68 return externalCmd{"arv"}.RunCommand("arv", legacyFlagsToFront(rc.subcommand, args), stdin, stdout, stderr)
71 type externalCmd struct {
75 func (ec externalCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
76 cmd := exec.Command(ec.prog, args...)
81 switch err := err.(type) {
85 status := err.Sys().(syscall.WaitStatus)
87 return status.ExitStatus()
89 fmt.Fprintf(stderr, "%s failed: %s\n", ec.prog, err)
92 fmt.Fprintln(stderr, err)
94 fmt.Fprint(stderr, rubyInstallHints)
95 } else if strings.HasPrefix(ec.prog, "arv-") {
96 fmt.Fprint(stderr, pythonInstallHints)
100 fmt.Fprintf(stderr, "error running %s: %s\n", ec.prog, err)
107 Note: This subcommand uses the arvados-cli Ruby gem. If that is not
108 installed, try "gem install arvados-cli", or see
109 https://doc.arvados.org/install for more details.
112 pythonInstallHints = `
113 Note: This subcommand uses the "arvados" Python module. If that is
115 * "pip install arvados" (either as root or in a virtualenv), or
116 * "sudo apt-get install python3-arvados-python-client", or
117 * see https://doc.arvados.org/install for more details.