Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): app subcommand #11

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cli/cmd/app/app.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion cli/cmd/deploy/cmd.go → cli/cmd/app/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -69,7 +69,7 @@ func TestDeploy(t *testing.T) {

t.Run("given invalid slug then it returns error", func(t *testing.T) {
appDir := t.TempDir()
copyTo(t, "../../testdata/streamlit_app", appDir)
copyTo(t, "../../../testdata/streamlit_app", appDir)

err := Deploy(context.TODO(), nil, appDir, "", "Some Invalid Organization Slug", appName, false)

Expand All @@ -78,7 +78,7 @@ func TestDeploy(t *testing.T) {

t.Run("given invalid app name then it returns error", func(t *testing.T) {
appDir := t.TempDir()
copyTo(t, "../../testdata/streamlit_app", appDir)
copyTo(t, "../../../testdata/streamlit_app", appDir)

err := Deploy(context.TODO(), nil, appDir, "", slug, "Some Invalid App Name", false)

Expand All @@ -87,7 +87,7 @@ func TestDeploy(t *testing.T) {

t.Run("given no slug or app name arguments and manifest with deployment and then it uses manifest deployment", 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)
Expand All @@ -108,7 +108,7 @@ func TestDeploy(t *testing.T) {

t.Run("given slug or app name arguments and manifest with deployment and then arguments override manifest deployment", 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)
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions cli/cmd/organization/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package organization
import (
"os"

"numerous/cli/cmd/organization/create"
"numerous/cli/cmd/organization/list"

"github.com/spf13/cobra"
)

Expand All @@ -19,3 +22,8 @@ var OrganizationRootCmd = &cobra.Command{
return nil
},
}

func init() {
OrganizationRootCmd.AddCommand(create.OrganizationCreateCmd)
OrganizationRootCmd.AddCommand(list.OrganizationListCmd)
}
10 changes: 3 additions & 7 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ 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"
"numerous/cli/cmd/log"
"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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down