1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
15 "git.curoverse.com/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"}
25 Run = externalCmd{"arv-run"}
27 Keep = cmd.Multi(map[string]cmd.Handler{
28 "get": externalCmd{"arv-get"},
29 "put": externalCmd{"arv-put"},
30 "ls": externalCmd{"arv-ls"},
31 "normalize": externalCmd{"arv-normalize"},
32 "docker": externalCmd{"arv-keepdocker"},
34 Pipeline = cmd.Multi(map[string]cmd.Handler{
35 "run": externalCmd{"arv-run-pipeline-instance"},
37 // user, group, container, specimen, etc.
38 APICall = apiCallCmd{}
41 // When using the ruby "arv" command, flags must come before the
42 // subcommand: "arv --format=yaml get foo" works, but "arv get
43 // --format=yaml foo" does not work.
44 func legacyFlagsToFront(subcommand string, argsin []string) (argsout []string) {
45 flags, _ := LegacyFlagSet()
46 flags.SetOutput(ioutil.Discard)
49 argsout = append(argsout, argsin[:len(argsin)-narg]...)
50 argsout = append(argsout, subcommand)
51 argsout = append(argsout, argsin[len(argsin)-narg:]...)
55 type apiCallCmd struct{}
57 func (cmd apiCallCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
58 split := strings.Split(prog, " ")
60 fmt.Fprintf(stderr, "internal error: no api model in %q\n", prog)
63 model := split[len(split)-1]
64 return externalCmd{"arv"}.RunCommand("arv", legacyFlagsToFront(model, args), stdin, stdout, stderr)
67 type rubyArvCmd struct {
71 func (rc rubyArvCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
72 return externalCmd{"arv"}.RunCommand("arv", legacyFlagsToFront(rc.subcommand, args), stdin, stdout, stderr)
75 type externalCmd struct {
79 func (ec externalCmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
80 cmd := exec.Command(ec.prog, args...)
85 switch err := err.(type) {
89 status := err.Sys().(syscall.WaitStatus)
91 return status.ExitStatus()
93 fmt.Fprintf(stderr, "%s failed: %s\n", ec.prog, err)
96 fmt.Fprintln(stderr, err)
97 if ec.prog == "arv" || ec.prog == "arv-run-pipeline-instance" {
98 fmt.Fprint(stderr, rubyInstallHints)
99 } else if strings.HasPrefix(ec.prog, "arv-") {
100 fmt.Fprint(stderr, pythonInstallHints)
104 fmt.Fprintf(stderr, "error running %s: %s\n", ec.prog, err)
111 Note: This subcommand uses the arvados-cli Ruby gem. If that is not
112 installed, try "gem install arvados-cli", or see
113 https://doc.arvados.org/install for more details.
116 pythonInstallHints = `
117 Note: This subcommand uses the "arvados" Python module. If that is
119 * "pip install arvados" (either as root or in a virtualenv), or
120 * "sudo apt-get install python-arvados-python-client", or
121 * see https://doc.arvados.org/install for more details.