From a0fe5c28d667f11fbe3f470019d5b2beab058704 Mon Sep 17 00:00:00 2001 From: Vipul Vaibhaw Date: Wed, 13 Mar 2024 14:57:11 +0530 Subject: [PATCH 1/3] adding quickstart cmd --- cmd/quickstart/quickstart.go | 32 ++++++++++++++++++++++++++++++++ cmd/root.go | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 cmd/quickstart/quickstart.go diff --git a/cmd/quickstart/quickstart.go b/cmd/quickstart/quickstart.go new file mode 100644 index 00000000..7d44562d --- /dev/null +++ b/cmd/quickstart/quickstart.go @@ -0,0 +1,32 @@ +package quickstart + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" +) + +func NewCmd() *cobra.Command { + var quickstartcmd = cobra.Command{ + Use: "quickstart [sdk]", + Short: "Create a minimal getting started app for the specified SDK", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + sdk := args[0] + switch strings.ToLower(sdk) { + case "ts", "typescript": + printInstructionsForTypeScript() + default: + fmt.Printf("Error: Unknown SDK '%s'.\n", sdk) + } + }, + } + return &quickstartcmd +} + +func printInstructionsForTypeScript() { + fmt.Println("Getting started with Resonate for TypeScript") + fmt.Println("> 🏴‍☠️ 1. Run git clone git@github.com:resonatehq/ts-quickstart.git quickstart && cd quickstart") + fmt.Println("> 🏴‍☠️ 2. Follow the Getting Started instructions in Readme.md") +} diff --git a/cmd/root.go b/cmd/root.go index 3dec80f4..3c5fa4bc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,6 +7,7 @@ import ( "github.com/resonatehq/resonate/cmd/dst" "github.com/resonatehq/resonate/cmd/promises" + "github.com/resonatehq/resonate/cmd/quickstart" "github.com/resonatehq/resonate/cmd/schedules" "github.com/resonatehq/resonate/cmd/serve" "github.com/resonatehq/resonate/pkg/client" @@ -40,6 +41,7 @@ func init() { rootCmd.AddCommand(schedules.NewCmd(c)) rootCmd.AddCommand(dst.NewCmd()) rootCmd.AddCommand(serve.ServeCmd()) + rootCmd.AddCommand(quickstart.NewCmd()) // Set default output rootCmd.SetOut(os.Stdout) From 4719c9020037ef880999566c619ec6d34b23f598 Mon Sep 17 00:00:00 2001 From: Vipul Vaibhaw Date: Wed, 13 Mar 2024 19:37:03 +0530 Subject: [PATCH 2/3] code refactor --- cmd/quickstart/quickstart.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/quickstart/quickstart.go b/cmd/quickstart/quickstart.go index 7d44562d..36155ae1 100644 --- a/cmd/quickstart/quickstart.go +++ b/cmd/quickstart/quickstart.go @@ -16,7 +16,7 @@ func NewCmd() *cobra.Command { sdk := args[0] switch strings.ToLower(sdk) { case "ts", "typescript": - printInstructionsForTypeScript() + printInstructions(sdk) default: fmt.Printf("Error: Unknown SDK '%s'.\n", sdk) } @@ -25,8 +25,13 @@ func NewCmd() *cobra.Command { return &quickstartcmd } -func printInstructionsForTypeScript() { - fmt.Println("Getting started with Resonate for TypeScript") - fmt.Println("> 🏴‍☠️ 1. Run git clone git@github.com:resonatehq/ts-quickstart.git quickstart && cd quickstart") - fmt.Println("> 🏴‍☠️ 2. Follow the Getting Started instructions in Readme.md") +func printInstructions(lang string) { + switch strings.ToLower(lang) { + case "ts", "typescript": + fmt.Println("Getting started with Resonate for TypeScript") + fmt.Println("> 🏴‍☠️ 1. Run git clone git@github.com:resonatehq/resonate-sdk-ts.git ts-quickstart && cd ts-quickstart") + fmt.Println("> 🏴‍☠️ 2. Follow the Getting Started instructions in Readme.md") + default: + fmt.Printf("Error: Unknown SDK '%s'.\n", lang) + } } From 71a488c5d68bc04b0ca8f198e1d1662f2aec4f56 Mon Sep 17 00:00:00 2001 From: Vipul Vaibhaw Date: Wed, 13 Mar 2024 21:51:37 +0530 Subject: [PATCH 3/3] code refactor and use cmd.println --- cmd/quickstart/quickstart.go | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/cmd/quickstart/quickstart.go b/cmd/quickstart/quickstart.go index 36155ae1..cf4e92fa 100644 --- a/cmd/quickstart/quickstart.go +++ b/cmd/quickstart/quickstart.go @@ -1,37 +1,25 @@ package quickstart import ( - "fmt" - "strings" - "github.com/spf13/cobra" ) func NewCmd() *cobra.Command { - var quickstartcmd = cobra.Command{ + var quickstartCmd = &cobra.Command{ Use: "quickstart [sdk]", Short: "Create a minimal getting started app for the specified SDK", Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { sdk := args[0] - switch strings.ToLower(sdk) { - case "ts", "typescript": - printInstructions(sdk) - default: - fmt.Printf("Error: Unknown SDK '%s'.\n", sdk) - } + printInstructionsFor(sdk, sdk, cmd) + return nil }, } - return &quickstartcmd + return quickstartCmd } -func printInstructions(lang string) { - switch strings.ToLower(lang) { - case "ts", "typescript": - fmt.Println("Getting started with Resonate for TypeScript") - fmt.Println("> 🏴‍☠️ 1. Run git clone git@github.com:resonatehq/resonate-sdk-ts.git ts-quickstart && cd ts-quickstart") - fmt.Println("> 🏴‍☠️ 2. Follow the Getting Started instructions in Readme.md") - default: - fmt.Printf("Error: Unknown SDK '%s'.\n", lang) - } +func printInstructionsFor(language, alias string, cmd *cobra.Command) { + cmd.Printf("Getting started with Resonate for %s\n", alias) + cmd.Println("> 🏴‍☠️ 1. Run git clone git@github.com:resonatehq/" + language + "-quickstart.git quickstart && cd quickstart") + cmd.Println("> 🏴‍☠️ 2. Follow the Getting Started instructions in Readme.md") }