12876: Pass commands through to ruby/python programs.
[arvados.git] / cmd / arvados-client / cmd.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package main
6
7 import (
8         "fmt"
9         "io"
10         "os"
11         "regexp"
12         "runtime"
13
14         "git.curoverse.com/arvados.git/lib/cli"
15         "git.curoverse.com/arvados.git/lib/cmd"
16 )
17
18 var (
19         version                = "dev"
20         cmdVersion cmd.Handler = versionCmd{}
21         handler                = cmd.Multi(map[string]cmd.Handler{
22                 "-e":        cmdVersion,
23                 "version":   cmdVersion,
24                 "-version":  cmdVersion,
25                 "--version": cmdVersion,
26
27                 "copy":     cli.Copy,
28                 "create":   cli.Create,
29                 "edit":     cli.Edit,
30                 "get":      cli.Get,
31                 "keep":     cli.Keep,
32                 "pipeline": cli.Pipeline,
33                 "run":      cli.Run,
34                 "tag":      cli.Tag,
35                 "ws":       cli.Ws,
36
37                 "api_client_authorization": cli.APICall,
38                 "api_client":               cli.APICall,
39                 "authorized_key":           cli.APICall,
40                 "collection":               cli.APICall,
41                 "container":                cli.APICall,
42                 "container_request":        cli.APICall,
43                 "group":                    cli.APICall,
44                 "human":                    cli.APICall,
45                 "job":                      cli.APICall,
46                 "job_task":                 cli.APICall,
47                 "keep_disk":                cli.APICall,
48                 "keep_service":             cli.APICall,
49                 "link":                     cli.APICall,
50                 "log":                      cli.APICall,
51                 "node":                     cli.APICall,
52                 "pipeline_instance":        cli.APICall,
53                 "pipeline_template":        cli.APICall,
54                 "repository":               cli.APICall,
55                 "specimen":                 cli.APICall,
56                 "trait":                    cli.APICall,
57                 "user_agreement":           cli.APICall,
58                 "user":                     cli.APICall,
59                 "virtual_machine":          cli.APICall,
60                 "workflow":                 cli.APICall,
61         })
62 )
63
64 type versionCmd struct{}
65
66 func (versionCmd) RunCommand(prog string, args []string, _ io.Reader, stdout, _ io.Writer) int {
67         prog = regexp.MustCompile(` -*version$`).ReplaceAllLiteralString(prog, "")
68         fmt.Fprintf(stdout, "%s %s (%s)\n", prog, version, runtime.Version())
69         return 0
70 }
71
72 func fixLegacyArgs(args []string) []string {
73         flags, _ := cli.LegacyFlagSet()
74         return cmd.SubcommandToFront(args, flags)
75 }
76
77 func main() {
78         os.Exit(handler.RunCommand(os.Args[0], fixLegacyArgs(os.Args[1:]), os.Stdin, os.Stdout, os.Stderr))
79 }