From 281cfcfc0052e91b93e5ee23a70b4cabfbddae3f Mon Sep 17 00:00:00 2001 From: David Farr Date: Thu, 13 Feb 2025 19:01:52 -0800 Subject: [PATCH] Cleanup projects cli command --- cmd/{project => projects}/create.go | 38 +++++++------------ cmd/{project => projects}/list.go | 6 +-- .../project.go => projects/projects.go} | 8 ++-- cmd/{project => projects}/scaffold.go | 2 +- cmd/root.go | 12 +++--- 5 files changed, 27 insertions(+), 39 deletions(-) rename cmd/{project => projects}/create.go (60%) rename cmd/{project => projects}/list.go (78%) rename cmd/{project/project.go => projects/projects.go} (89%) rename cmd/{project => projects}/scaffold.go (99%) diff --git a/cmd/project/create.go b/cmd/projects/create.go similarity index 60% rename from cmd/project/create.go rename to cmd/projects/create.go index 2d4b0cf4..56dda8f1 100644 --- a/cmd/project/create.go +++ b/cmd/projects/create.go @@ -1,7 +1,6 @@ -package project +package projects import ( - "errors" "fmt" "os" @@ -15,16 +14,19 @@ func CreateProjectCmd() *cobra.Command { ) exampleCMD := ` - resonate project create --name my-app --template py - resonate project create -n my-app -t py - ` +resonate projects create --template py +resonate projects create --template py --name my-app` cmd := &cobra.Command{ Use: "create", - Short: "Create a new resonate application node project", + Short: "Create a new resonate project", Example: exampleCMD, RunE: func(cmd *cobra.Command, args []string) error { - if err := validate(template, name); err != nil { + if name == "" { + name = template + } + + if err := validate(name); err != nil { return err } @@ -32,35 +34,21 @@ func CreateProjectCmd() *cobra.Command { return err } - fmt.Printf("\nproject successfully created in folder %s\n", name) + cmd.Printf("Template '%s' successfully copied to folder '%s'\n", template, name) return nil }, } - cmd.Flags().StringVarP(&name, "name", "n", "", "name of the project") cmd.Flags().StringVarP(&template, "template", "t", "", "name of the template, run 'resonate project list' to view available templates") + cmd.Flags().StringVarP(&name, "name", "n", "", "name of the project") - _ = cmd.MarkFlagRequired("name") _ = cmd.MarkFlagRequired("template") return cmd } -func validate(project, name string) error { - if name == "" { - return errors.New("a folder name is required") - } - - if project == "" { - return errors.New("project name is required") - } - - err := checkFolderExists(name) - if err != nil { - return err - } - - return nil +func validate(name string) error { + return checkFolderExists(name) } func checkFolderExists(name string) error { diff --git a/cmd/project/list.go b/cmd/projects/list.go similarity index 78% rename from cmd/project/list.go rename to cmd/projects/list.go index 1025b654..fe26ec41 100644 --- a/cmd/project/list.go +++ b/cmd/projects/list.go @@ -1,4 +1,4 @@ -package project +package projects import ( "fmt" @@ -9,7 +9,7 @@ import ( func ListProjectCmd() *cobra.Command { cmd := &cobra.Command{ Use: "list", - Short: "List the available application node projects", + Short: "List resonate projects", Example: "resonate project list", RunE: func(cmd *cobra.Command, args []string) error { templates, err := GetProjects() @@ -27,6 +27,6 @@ func ListProjectCmd() *cobra.Command { func display(templates Projects) { for name, t := range templates { - fmt.Printf("\n%s\n\t%s\n", name, t.Desc) + fmt.Printf("%s:\n\t%s\n", name, t.Desc) } } diff --git a/cmd/project/project.go b/cmd/projects/projects.go similarity index 89% rename from cmd/project/project.go rename to cmd/projects/projects.go index f50c1c15..173f22b8 100644 --- a/cmd/project/project.go +++ b/cmd/projects/projects.go @@ -1,4 +1,4 @@ -package project +package projects import ( "encoding/json" @@ -19,16 +19,16 @@ type ( func NewCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "project", + Use: "projects", Aliases: []string{"project"}, - Short: "Resonate application node projects", + Short: "Resonate projects", Run: func(cmd *cobra.Command, args []string) { _ = cmd.Help() }, } // Add subcommands - cmd.AddCommand(ListProjectCmd()) // list available projects + cmd.AddCommand(ListProjectCmd()) // list projects cmd.AddCommand(CreateProjectCmd()) // create a project return cmd diff --git a/cmd/project/scaffold.go b/cmd/projects/scaffold.go similarity index 99% rename from cmd/project/scaffold.go rename to cmd/projects/scaffold.go index eee0b532..3acd4d45 100644 --- a/cmd/project/scaffold.go +++ b/cmd/projects/scaffold.go @@ -1,4 +1,4 @@ -package project +package projects import ( "archive/zip" diff --git a/cmd/root.go b/cmd/root.go index 69075b1d..16b0661c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,7 +7,7 @@ import ( "github.com/resonatehq/resonate/cmd/callbacks" "github.com/resonatehq/resonate/cmd/dst" - "github.com/resonatehq/resonate/cmd/project" + "github.com/resonatehq/resonate/cmd/projects" "github.com/resonatehq/resonate/cmd/promises" "github.com/resonatehq/resonate/cmd/quickstart" "github.com/resonatehq/resonate/cmd/schedules" @@ -36,15 +36,15 @@ func init() { rootCmd.PersistentFlags().StringP("log-level", "", "info", "can be one of: debug, info, warn, error") // Add Subcommands + rootCmd.AddCommand(callbacks.NewCmd()) + rootCmd.AddCommand(dst.NewCmd()) + rootCmd.AddCommand(projects.NewCmd()) rootCmd.AddCommand(promises.NewCmd()) + rootCmd.AddCommand(quickstart.NewCmd()) rootCmd.AddCommand(schedules.NewCmd()) - rootCmd.AddCommand(dst.NewCmd()) rootCmd.AddCommand(serve.ServeCmd()) - rootCmd.AddCommand(quickstart.NewCmd()) - rootCmd.AddCommand(tasks.NewCmd()) - rootCmd.AddCommand(callbacks.NewCmd()) - rootCmd.AddCommand(project.NewCmd()) rootCmd.AddCommand(subscriptions.NewCmd()) + rootCmd.AddCommand(tasks.NewCmd()) // Set default output rootCmd.SetOut(os.Stdout)