From 4c54cc43537fd15cc459030cb792f8171bcd0fd7 Mon Sep 17 00:00:00 2001 From: Martin Treusch von Buttlar Date: Mon, 15 May 2017 22:39:14 +0200 Subject: add cobra commands --- cmd/ponzu/add.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'cmd/ponzu/add.go') diff --git a/cmd/ponzu/add.go b/cmd/ponzu/add.go index 05d6f16..c1242db 100644 --- a/cmd/ponzu/add.go +++ b/cmd/ponzu/add.go @@ -8,15 +8,35 @@ import ( "os/exec" "path/filepath" "strings" + + "github.com/spf13/cobra" ) +var addCmd = &cobra.Command{ + Use: "add ", + Short: "Downloads addon from specified import path", + Long: `Downloads addon from specified import path to $GOPATH/src and copys it to the +current project's ./addons directory. Must be called from within a +Ponzu project directory. + +Example: +$ ponzu add github.com/bosssauce/fbscheduler`, + RunE: func(cmd *cobra.Command, args []string) error { + // expecting two args, add and the go gettable package uri + if len(args) < 1 { + return errors.New("repo not given") + } + + return getAddon(args[0]) + }, +} + // use `go get` to download addon and add to $GOPATH/src, useful // for IDE auto-import and code completion, then copy entire directory // tree to project's ./addons folder -func getAddon(args []string) error { +func getAddon(addonPath string) error { var cmdOptions []string - var addonPath = args[1] // Go get cmdOptions = append(cmdOptions, "get", addonPath) @@ -165,3 +185,7 @@ func copyFileContents(src, dst string) (err error) { func addError(err error) error { return errors.New("Ponzu add failed. " + "\n" + err.Error()) } + +func init() { + rootCmd.AddCommand(addCmd) +} -- cgit v1.2.3 From d89c33c1398428d4a456ca0252e6b1718efb0b96 Mon Sep 17 00:00:00 2001 From: Martin Treusch von Buttlar Date: Tue, 16 May 2017 06:40:54 +0200 Subject: move usage examples to cobra field of same name --- cmd/ponzu/add.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'cmd/ponzu/add.go') diff --git a/cmd/ponzu/add.go b/cmd/ponzu/add.go index c1242db..7832b4e 100644 --- a/cmd/ponzu/add.go +++ b/cmd/ponzu/add.go @@ -17,10 +17,8 @@ var addCmd = &cobra.Command{ Short: "Downloads addon from specified import path", Long: `Downloads addon from specified import path to $GOPATH/src and copys it to the current project's ./addons directory. Must be called from within a -Ponzu project directory. - -Example: -$ ponzu add github.com/bosssauce/fbscheduler`, +Ponzu project directory.`, + Example: `$ ponzu add github.com/bosssauce/fbscheduler`, RunE: func(cmd *cobra.Command, args []string) error { // expecting two args, add and the go gettable package uri if len(args) < 1 { -- cgit v1.2.3 From 99bae528846f2fb900ff1168c1e143181f89e597 Mon Sep 17 00:00:00 2001 From: Martin Treusch von Buttlar Date: Wed, 17 May 2017 07:19:05 +0200 Subject: add shorthand commands for add, generate, serve and version --- cmd/ponzu/add.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cmd/ponzu/add.go') diff --git a/cmd/ponzu/add.go b/cmd/ponzu/add.go index 7832b4e..533c171 100644 --- a/cmd/ponzu/add.go +++ b/cmd/ponzu/add.go @@ -13,8 +13,9 @@ import ( ) var addCmd = &cobra.Command{ - Use: "add ", - Short: "Downloads addon from specified import path", + Use: "add ", + Aliases: []string{"a"}, + Short: "Downloads addon from specified import path", Long: `Downloads addon from specified import path to $GOPATH/src and copys it to the current project's ./addons directory. Must be called from within a Ponzu project directory.`, -- cgit v1.2.3 From 0e98babf9b4f9084d7e29b0f484f64ba62dc265b Mon Sep 17 00:00:00 2001 From: Martin Treusch von Buttlar Date: Wed, 17 May 2017 07:19:36 +0200 Subject: refactor code which starts external commands --- cmd/ponzu/add.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'cmd/ponzu/add.go') diff --git a/cmd/ponzu/add.go b/cmd/ponzu/add.go index 533c171..db8aa2e 100644 --- a/cmd/ponzu/add.go +++ b/cmd/ponzu/add.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "os/exec" "path/filepath" "strings" @@ -39,15 +38,7 @@ func getAddon(addonPath string) error { // Go get cmdOptions = append(cmdOptions, "get", addonPath) - get := exec.Command(gocmd, cmdOptions...) - get.Stderr = os.Stderr - get.Stdout = os.Stdout - - err := get.Start() - if err != nil { - return addError(err) - } - err = get.Wait() + err := execAndWait(gocmd, cmdOptions...) if err != nil { return addError(err) } -- cgit v1.2.3 From 9f4c550b8be0f80fd670f7ded32dbd4aab8d1f4e Mon Sep 17 00:00:00 2001 From: Martin Treusch von Buttlar Date: Mon, 22 May 2017 09:00:23 +0200 Subject: add help flags for sub commands to root cmd --- cmd/ponzu/add.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd/ponzu/add.go') diff --git a/cmd/ponzu/add.go b/cmd/ponzu/add.go index db8aa2e..30cf168 100644 --- a/cmd/ponzu/add.go +++ b/cmd/ponzu/add.go @@ -177,5 +177,5 @@ func addError(err error) error { } func init() { - rootCmd.AddCommand(addCmd) + RegisterCmdlineCommand(addCmd) } -- cgit v1.2.3 From ba0166f681e054afd6a3c9192ea1c68e6d7bc6a5 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 22 May 2017 01:56:17 -0700 Subject: updating usage notes and multi-word formatted flags --- cmd/ponzu/add.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'cmd/ponzu/add.go') diff --git a/cmd/ponzu/add.go b/cmd/ponzu/add.go index 30cf168..f4b9fea 100644 --- a/cmd/ponzu/add.go +++ b/cmd/ponzu/add.go @@ -12,17 +12,16 @@ import ( ) var addCmd = &cobra.Command{ - Use: "add ", + Use: "add ", Aliases: []string{"a"}, Short: "Downloads addon from specified import path", Long: `Downloads addon from specified import path to $GOPATH/src and copys it to the -current project's ./addons directory. Must be called from within a -Ponzu project directory.`, +current project's addons directory. Must be called from within a Ponzu project directory.`, Example: `$ ponzu add github.com/bosssauce/fbscheduler`, RunE: func(cmd *cobra.Command, args []string) error { - // expecting two args, add and the go gettable package uri + // expecting two args, add/a and the go gettable package uri if len(args) < 1 { - return errors.New("repo not given") + return errors.New("no import path provided") } return getAddon(args[0]) -- cgit v1.2.3