veyron/tools/binary: Create packages dynamically
With this change, the binary upload command will create a package on the
fly when its argument is a directory.
Change-Id: Ib539287fbef247fe0c9220c94469734ddc339e38
diff --git a/tools/binary/impl.go b/tools/binary/impl.go
index b51f7fd..3f8ebd3 100644
--- a/tools/binary/impl.go
+++ b/tools/binary/impl.go
@@ -2,6 +2,7 @@
import (
"fmt"
+ "os"
"v.io/core/veyron/services/mgmt/lib/binary"
"v.io/lib/cmdline"
@@ -71,11 +72,21 @@
}
func runUpload(cmd *cmdline.Command, args []string) error {
- // TODO(rthellend): Add support for creating packages on the fly.
if expected, got := 2, len(args); expected != got {
return cmd.UsageErrorf("upload: incorrect number of arguments, expected %d, got %d", expected, got)
}
von, filename := args[0], args[1]
+ fi, err := os.Stat(filename)
+ if err != nil {
+ return err
+ }
+ if fi.IsDir() {
+ if err := binary.UploadFromDir(gctx, von, filename); err != nil {
+ return err
+ }
+ fmt.Fprintf(cmd.Stdout(), "Binary package uploaded from directory %s\n", filename)
+ return nil
+ }
if err := binary.UploadFromFile(gctx, von, filename); err != nil {
return err
}