[ARVADOS] updated: 1.1.2-9-gb851f17

Git user git at public.curoverse.com
Sat Dec 23 01:27:03 EST 2017


Summary of changes:
 build/run-tests.sh        |  2 ++
 cmd/arvados-client/cmd.go |  5 +++--
 lib/cli/get.go            | 14 ++++++++++++-
 lib/cli/get_test.go       | 33 +++++++++++++++++++++++++++++++
 lib/cmd/cmd.go            | 34 ++++++++++++++++++++++++++++++++
 lib/cmd/cmd_test.go       | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 135 insertions(+), 3 deletions(-)
 create mode 100644 lib/cli/get_test.go
 create mode 100644 lib/cmd/cmd_test.go

       via  b851f17a590bf423bbe0bce033fa1d40738c96a9 (commit)
       via  70fa8cfd92fc089f698b70276234d346429673e9 (commit)
      from  23d47cde9897110f071682f92f4064db3c473811 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit b851f17a590bf423bbe0bce033fa1d40738c96a9
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Sat Dec 23 01:26:28 2017 -0500

    12868: More compatibility with "arv get".
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/cmd/arvados-client/cmd.go b/cmd/arvados-client/cmd.go
index 0df1b0c..b96cce3 100644
--- a/cmd/arvados-client/cmd.go
+++ b/cmd/arvados-client/cmd.go
@@ -17,12 +17,13 @@ import (
 
 var version = "dev"
 
-var Run = cmd.Multi(map[string]cmd.RunFunc{
+var Run = cmd.WithLateSubcommand(cmd.Multi(map[string]cmd.RunFunc{
 	"get":       cli.Get,
+	"-e":        cmdVersion,
 	"version":   cmdVersion,
 	"-version":  cmdVersion,
 	"--version": cmdVersion,
-})
+}), []string{"f", "format"}, []string{"n", "dry-run", "v", "verbose", "s", "short"})
 
 func cmdVersion(prog string, args []string, _ io.Reader, stdout, _ io.Writer) int {
 	prog = regexp.MustCompile(` -*version$`).ReplaceAllLiteralString(prog, "")
diff --git a/lib/cli/get.go b/lib/cli/get.go
index 725c696..a7adfb6 100644
--- a/lib/cli/get.go
+++ b/lib/cli/get.go
@@ -23,7 +23,14 @@ func Get(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer)
 	}()
 
 	flags := flag.NewFlagSet(prog, flag.ContinueOnError)
-	format := flags.String("format", "json", "output format (json or yaml)")
+	format := flags.String("format", "json", "output format (json, yaml, or uuid)")
+	flags.StringVar(format, "f", "json", "output format (json, yaml, or uuid)")
+	short := flags.Bool("short", false, "equivalent to --format=uuid")
+	flags.BoolVar(short, "s", false, "equivalent to --format=uuid")
+	flags.Bool("dry-run", false, "dry run (ignored, for compatibility)")
+	flags.Bool("n", false, "dry run (ignored, for compatibility)")
+	flags.Bool("verbose", false, "verbose (ignored, for compatibility)")
+	flags.Bool("v", false, "verbose (ignored, for compatibility)")
 	err = flags.Parse(args)
 	if err != nil {
 		return 2
@@ -32,6 +39,9 @@ func Get(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer)
 		flags.Usage()
 		return 2
 	}
+	if *short {
+		*format = "uuid"
+	}
 
 	id := flags.Args()[0]
 	client := arvados.NewClientFromEnv()
@@ -52,6 +62,8 @@ func Get(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer)
 		if err == nil {
 			_, err = stdout.Write(buf)
 		}
+	} else if *format == "uuid" {
+		fmt.Fprintln(stdout, obj["uuid"])
 	} else {
 		enc := json.NewEncoder(stdout)
 		enc.SetIndent("", "  ")
diff --git a/lib/cli/get_test.go b/lib/cli/get_test.go
new file mode 100644
index 0000000..9b8f1a0
--- /dev/null
+++ b/lib/cli/get_test.go
@@ -0,0 +1,33 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package cli
+
+import (
+	"bytes"
+	"regexp"
+	"testing"
+
+	"git.curoverse.com/arvados.git/sdk/go/arvadostest"
+	check "gopkg.in/check.v1"
+)
+
+// Gocheck boilerplate
+func Test(t *testing.T) {
+	check.TestingT(t)
+}
+
+var _ = check.Suite(&GetSuite{})
+
+type GetSuite struct{}
+
+func (s *GetSuite) TestGetCollectionJSON(c *check.C) {
+	stdout := bytes.NewBuffer(nil)
+	stderr := bytes.NewBuffer(nil)
+	exited := Get("arvados-client get", []string{arvadostest.FooCollection}, bytes.NewReader(nil), stdout, stderr)
+	c.Check(stdout.String(), check.Matches, `(?ms){.*"uuid": "`+arvadostest.FooCollection+`".*}\n`)
+	c.Check(stdout.String(), check.Matches, `(?ms){.*"portable_data_hash": "`+regexp.QuoteMeta(arvadostest.FooCollectionPDH)+`".*}\n`)
+	c.Check(stderr.String(), check.Equals, "")
+	c.Check(exited, check.Equals, 0)
+}

commit 70fa8cfd92fc089f698b70276234d346429673e9
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Sat Dec 23 01:14:11 2017 -0500

    12868: Util to accept subcommand after initial args.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/build/run-tests.sh b/build/run-tests.sh
index 5114cef..46418be 100755
--- a/build/run-tests.sh
+++ b/build/run-tests.sh
@@ -72,6 +72,7 @@ apps/workbench_profile
 cmd/arvados-client
 doc
 lib/cli
+lib/cmd
 lib/crunchstat
 services/api
 services/arv-git-httpd
@@ -834,6 +835,7 @@ declare -a gostuff
 gostuff=(
     cmd/arvados-client
     lib/cli
+    lib/cmd
     lib/crunchstat
     sdk/go/arvados
     sdk/go/arvadosclient
diff --git a/lib/cmd/cmd.go b/lib/cmd/cmd.go
index 03b751a..a3d5ae8 100644
--- a/lib/cmd/cmd.go
+++ b/lib/cmd/cmd.go
@@ -7,6 +7,7 @@
 package cmd
 
 import (
+	"flag"
 	"fmt"
 	"io"
 )
@@ -42,3 +43,36 @@ func Multi(m map[string]RunFunc) RunFunc {
 		}
 	}
 }
+
+// WithLateSubcommand wraps a RunFunc by skipping over some known
+// flags to find a subcommand, and moving that subcommand to the front
+// of the args before calling the wrapped RunFunc. For example:
+//
+//	// Translate [           --format foo subcommand bar]
+//	//        to [subcommand --format foo            bar]
+//	WithLateSubcommand(fn, []string{"format"}, nil)
+func WithLateSubcommand(run RunFunc, argFlags, boolFlags []string) RunFunc {
+	return func(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
+		flags := flag.NewFlagSet("prog", flag.ContinueOnError)
+		for _, arg := range argFlags {
+			flags.String(arg, "", "")
+		}
+		for _, arg := range boolFlags {
+			flags.Bool(arg, false, "")
+		}
+		// Ignore errors. We can't report a useful error
+		// message anyway.
+		flags.Parse(args)
+		if flags.NArg() > 0 {
+			// Move the first arg after the recognized
+			// flags up to the front.
+			flagargs := len(args) - flags.NArg()
+			newargs := make([]string, len(args))
+			newargs[0] = args[flagargs]
+			copy(newargs[1:flagargs+1], args[:flagargs])
+			copy(newargs[flagargs+1:], args[flagargs+1:])
+			args = newargs
+		}
+		return run(prog, args, stdin, stdout, stderr)
+	}
+}
diff --git a/lib/cmd/cmd_test.go b/lib/cmd/cmd_test.go
new file mode 100644
index 0000000..fc20bef
--- /dev/null
+++ b/lib/cmd/cmd_test.go
@@ -0,0 +1,50 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package cmd
+
+import (
+	"bytes"
+	"fmt"
+	"io"
+	"strings"
+	"testing"
+
+	check "gopkg.in/check.v1"
+)
+
+// Gocheck boilerplate
+func Test(t *testing.T) {
+	check.TestingT(t)
+}
+
+var _ = check.Suite(&CmdSuite{})
+
+type CmdSuite struct{}
+
+var testCmd = Multi(map[string]RunFunc{
+	"echo": func(prog string, args []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) int {
+		fmt.Fprintln(stdout, strings.Join(args, " "))
+		return 0
+	},
+})
+
+func (s *CmdSuite) TestHello(c *check.C) {
+	stdout := bytes.NewBuffer(nil)
+	stderr := bytes.NewBuffer(nil)
+	exited := testCmd("prog", []string{"echo", "hello", "world"}, bytes.NewReader(nil), stdout, stderr)
+	c.Check(exited, check.Equals, 0)
+	c.Check(stdout.String(), check.Equals, "hello world\n")
+	c.Check(stderr.String(), check.Equals, "")
+}
+
+func (s *CmdSuite) TestWithLateSubcommand(c *check.C) {
+	stdout := bytes.NewBuffer(nil)
+	stderr := bytes.NewBuffer(nil)
+	run := WithLateSubcommand(testCmd, []string{"format", "f"}, []string{"n"})
+	exited := run("prog", []string{"--format=yaml", "-n", "-format", "beep", "echo", "hi"}, bytes.NewReader(nil), stdout, stderr)
+	c.Check(exited, check.Equals, 0)
+	c.Check(stdout.String(), check.Equals, "--format=yaml -n -format beep hi\n")
+	c.Check(stderr.String(), check.Equals, "")
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list