From 1036ab35ca3f197700301f795530564ce06255cf Mon Sep 17 00:00:00 2001 From: Frederik Date: Fri, 14 Jun 2024 14:15:27 +0200 Subject: [PATCH] feat(cli): app subcommand --- cli/cmd/app/app.go | 27 +++++++++++++++++++++++++ cli/cmd/{ => app}/deploy/cmd.go | 2 +- cli/cmd/{ => app}/deploy/deploy.go | 0 cli/cmd/{ => app}/deploy/deploy_test.go | 4 ++-- cli/cmd/{ => app}/deploy/mock.go | 0 cli/cmd/organization/organization.go | 8 ++++++++ cli/cmd/root.go | 10 +++------ 7 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 cli/cmd/app/app.go rename cli/cmd/{ => app}/deploy/cmd.go (96%) rename cli/cmd/{ => app}/deploy/deploy.go (100%) rename cli/cmd/{ => app}/deploy/deploy_test.go (97%) rename cli/cmd/{ => app}/deploy/mock.go (100%) diff --git a/cli/cmd/app/app.go b/cli/cmd/app/app.go new file mode 100644 index 0000000..05b87ee --- /dev/null +++ b/cli/cmd/app/app.go @@ -0,0 +1,27 @@ +package app + +import ( + "os" + + "numerous/cli/cmd/app/deploy" + + "github.com/spf13/cobra" +) + +var AppRootCmd = &cobra.Command{ + Use: "app", + Args: func(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + if err := cmd.Help(); err != nil { + return err + } + os.Exit(0) + } + + return nil + }, +} + +func init() { + AppRootCmd.AddCommand(deploy.DeployCmd) +} diff --git a/cli/cmd/deploy/cmd.go b/cli/cmd/app/deploy/cmd.go similarity index 96% rename from cli/cmd/deploy/cmd.go rename to cli/cmd/app/deploy/cmd.go index 29bd91c..0e28e72 100644 --- a/cli/cmd/deploy/cmd.go +++ b/cli/cmd/app/deploy/cmd.go @@ -32,7 +32,7 @@ If an app has been initialized in the current working directory, and it should be pushed to the organization "organization-slug-a3ecfh2b", and the app name "my-app", the following command can be used: - numerous deploy --organization "organization-slug-a3ecfh2b" --name "my-app" + numerous app deploy --organization "organization-slug-a3ecfh2b" --name "my-app" `, Args: func(cmd *cobra.Command, args []string) error { if len(args) > 1 { diff --git a/cli/cmd/deploy/deploy.go b/cli/cmd/app/deploy/deploy.go similarity index 100% rename from cli/cmd/deploy/deploy.go rename to cli/cmd/app/deploy/deploy.go diff --git a/cli/cmd/deploy/deploy_test.go b/cli/cmd/app/deploy/deploy_test.go similarity index 97% rename from cli/cmd/deploy/deploy_test.go rename to cli/cmd/app/deploy/deploy_test.go index 57be4ed..5f4ea71 100644 --- a/cli/cmd/deploy/deploy_test.go +++ b/cli/cmd/app/deploy/deploy_test.go @@ -26,7 +26,7 @@ func TestDeploy(t *testing.T) { t.Run("give no existing app then happy path can run", func(t *testing.T) { appDir := t.TempDir() - copyTo(t, "../../testdata/streamlit_app", appDir) + copyTo(t, "../../../testdata/streamlit_app", appDir) apps := &mockAppService{} apps.On("ReadApp", mock.Anything, mock.Anything).Return(app.ReadAppOutput{}, app.ErrAppNotFound) @@ -44,7 +44,7 @@ func TestDeploy(t *testing.T) { t.Run("give existing app then it does not create app", func(t *testing.T) { appDir := t.TempDir() - copyTo(t, "../../testdata/streamlit_app", appDir) + copyTo(t, "../../../testdata/streamlit_app", appDir) apps := &mockAppService{} apps.On("ReadApp", mock.Anything, mock.Anything).Return(app.ReadAppOutput{AppID: appID}, nil) diff --git a/cli/cmd/deploy/mock.go b/cli/cmd/app/deploy/mock.go similarity index 100% rename from cli/cmd/deploy/mock.go rename to cli/cmd/app/deploy/mock.go diff --git a/cli/cmd/organization/organization.go b/cli/cmd/organization/organization.go index db1906a..cbcc3e9 100644 --- a/cli/cmd/organization/organization.go +++ b/cli/cmd/organization/organization.go @@ -3,6 +3,9 @@ package organization import ( "os" + "numerous/cli/cmd/organization/create" + "numerous/cli/cmd/organization/list" + "github.com/spf13/cobra" ) @@ -19,3 +22,8 @@ var OrganizationRootCmd = &cobra.Command{ return nil }, } + +func init() { + OrganizationRootCmd.AddCommand(create.OrganizationCreateCmd) + OrganizationRootCmd.AddCommand(list.OrganizationListCmd) +} diff --git a/cli/cmd/root.go b/cli/cmd/root.go index e69089d..fd38fc7 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -9,8 +9,8 @@ import ( "runtime" "numerous/cli/auth" + "numerous/cli/cmd/app" deleteapp "numerous/cli/cmd/delete" - "numerous/cli/cmd/deploy" "numerous/cli/cmd/dev" "numerous/cli/cmd/initialize" "numerous/cli/cmd/list" @@ -18,8 +18,6 @@ import ( "numerous/cli/cmd/login" "numerous/cli/cmd/logout" "numerous/cli/cmd/organization" - createorganization "numerous/cli/cmd/organization/create" - listorganization "numerous/cli/cmd/organization/list" "numerous/cli/cmd/publish" "numerous/cli/cmd/push" "numerous/cli/cmd/report" @@ -93,7 +91,7 @@ func commandRequiresAuthentication(invokedCommandName string) bool { "numerous log", "numerous organization create", "numerous organization list", - "numerous deploy", + "numerous app deploy", } for _, cmd := range commandsWithAuthRequired { @@ -118,9 +116,7 @@ func bindCommands() { rootCmd.AddCommand(list.ListCmd) rootCmd.AddCommand(report.ReportCmd) rootCmd.AddCommand(organization.OrganizationRootCmd) - rootCmd.AddCommand(deploy.DeployCmd) - organization.OrganizationRootCmd.AddCommand(createorganization.OrganizationCreateCmd) - organization.OrganizationRootCmd.AddCommand(listorganization.OrganizationListCmd) + rootCmd.AddCommand(app.AppRootCmd) } func Execute() {