blob: 1df23144548be50a603736196d3a375b5e910c25 [file] [log] [blame]
Robin Thellend18205cf2014-10-21 13:53:59 -07001package main
Jiri Simsab04fbb22014-06-27 17:38:04 -07002
3import (
4 "fmt"
Jiri Simsab04fbb22014-06-27 17:38:04 -07005
Jiri Simsa519c5072014-09-17 21:37:57 -07006 "veyron.io/veyron/veyron/lib/cmdline"
7 "veyron.io/veyron/veyron/services/mgmt/lib/binary"
Jiri Simsab04fbb22014-06-27 17:38:04 -07008)
9
10var cmdDelete = &cmdline.Command{
11 Run: runDelete,
12 Name: "delete",
13 Short: "Delete binary",
14 Long: "Delete connects to the binary repository and deletes the specified binary",
Jiri Simsa51d78fc2014-07-09 18:34:08 -070015 ArgsName: "<von>",
16 ArgsLong: "<von> is the veyron object name of the binary to delete",
Jiri Simsab04fbb22014-06-27 17:38:04 -070017}
18
19func runDelete(cmd *cmdline.Command, args []string) error {
20 if expected, got := 1, len(args); expected != got {
Todd Wanga615e4d2014-09-29 16:56:05 -070021 return cmd.UsageErrorf("delete: incorrect number of arguments, expected %d, got %d", expected, got)
Jiri Simsab04fbb22014-06-27 17:38:04 -070022 }
Jiri Simsa51d78fc2014-07-09 18:34:08 -070023 von := args[0]
24 if err := binary.Delete(von); err != nil {
Jiri Simsab04fbb22014-06-27 17:38:04 -070025 return err
26 }
27 fmt.Fprintf(cmd.Stdout(), "Binary deleted successfully\n")
28 return nil
29}
30
31var cmdDownload = &cmdline.Command{
32 Run: runDownload,
33 Name: "download",
34 Short: "Download binary",
35 Long: `
36Download connects to the binary repository, downloads the specified binary, and
37writes it to a file.
38`,
Jiri Simsa51d78fc2014-07-09 18:34:08 -070039 ArgsName: "<von> <filename>",
Jiri Simsab04fbb22014-06-27 17:38:04 -070040 ArgsLong: `
Jiri Simsa51d78fc2014-07-09 18:34:08 -070041<von> is the veyron object name of the binary to download
Jiri Simsab04fbb22014-06-27 17:38:04 -070042<filename> is the name of the file where the binary will be written
43`,
44}
45
46func runDownload(cmd *cmdline.Command, args []string) error {
47 if expected, got := 2, len(args); expected != got {
Todd Wanga615e4d2014-09-29 16:56:05 -070048 return cmd.UsageErrorf("download: incorrect number of arguments, expected %d, got %d", expected, got)
Jiri Simsab04fbb22014-06-27 17:38:04 -070049 }
Jiri Simsa51d78fc2014-07-09 18:34:08 -070050 von, filename := args[0], args[1]
51 if err := binary.DownloadToFile(von, filename); err != nil {
Jiri Simsab04fbb22014-06-27 17:38:04 -070052 return err
53 }
Jiri Simsab04fbb22014-06-27 17:38:04 -070054 fmt.Fprintf(cmd.Stdout(), "Binary downloaded to file %s\n", filename)
55 return nil
56}
57
58var cmdUpload = &cmdline.Command{
59 Run: runUpload,
60 Name: "upload",
61 Short: "Upload binary",
62 Long: `
63Upload connects to the binary repository and uploads the binary of the specified
64file. When successful, it writes the name of the new binary to stdout.
65`,
Jiri Simsa51d78fc2014-07-09 18:34:08 -070066 ArgsName: "<von> <filename>",
Jiri Simsab04fbb22014-06-27 17:38:04 -070067 ArgsLong: `
Jiri Simsa51d78fc2014-07-09 18:34:08 -070068<von> is the veyron object name of the binary to upload
Jiri Simsab04fbb22014-06-27 17:38:04 -070069<filename> is the name of the file to upload
70`,
71}
72
73func runUpload(cmd *cmdline.Command, args []string) error {
74 if expected, got := 2, len(args); expected != got {
Todd Wanga615e4d2014-09-29 16:56:05 -070075 return cmd.UsageErrorf("upload: incorrect number of arguments, expected %d, got %d", expected, got)
Jiri Simsab04fbb22014-06-27 17:38:04 -070076 }
Jiri Simsa51d78fc2014-07-09 18:34:08 -070077 von, filename := args[0], args[1]
78 if err := binary.UploadFromFile(von, filename); err != nil {
Jiri Simsab04fbb22014-06-27 17:38:04 -070079 return err
80 }
Jiri Simsa51d78fc2014-07-09 18:34:08 -070081 fmt.Fprintf(cmd.Stdout(), "Binary uploaded from file %s\n", filename)
Jiri Simsab04fbb22014-06-27 17:38:04 -070082 return nil
83}
84
Robin Thellend18205cf2014-10-21 13:53:59 -070085func root() *cmdline.Command {
Jiri Simsab04fbb22014-06-27 17:38:04 -070086 return &cmdline.Command{
Todd Wangfcb72a52014-10-01 09:53:56 -070087 Name: "binary",
88 Short: "Tool for interacting with the veyron binary repository",
89 Long: `
90The binary tool facilitates interaction with the veyron binary repository.
91`,
Jiri Simsab04fbb22014-06-27 17:38:04 -070092 Children: []*cmdline.Command{cmdDelete, cmdDownload, cmdUpload},
93 }
94}