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

Cleanup projects cli command #545

Merged
merged 1 commit into from
Feb 14, 2025
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
38 changes: 13 additions & 25 deletions cmd/project/create.go → cmd/projects/create.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package project
package projects

import (
"errors"
"fmt"
"os"

Expand All @@ -15,52 +14,41 @@
)

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`

Check warning on line 18 in cmd/projects/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/create.go#L17-L18

Added lines #L17 - L18 were not covered by tests

cmd := &cobra.Command{
Use: "create",
Short: "Create a new resonate application node project",
Short: "Create a new resonate project",

Check warning on line 22 in cmd/projects/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/create.go#L22

Added line #L22 was not covered by tests
Example: exampleCMD,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validate(template, name); err != nil {
if name == "" {
name = template
}

Check warning on line 27 in cmd/projects/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/create.go#L25-L27

Added lines #L25 - L27 were not covered by tests

if err := validate(name); err != nil {

Check warning on line 29 in cmd/projects/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/create.go#L29

Added line #L29 was not covered by tests
return err
}

if err := scaffold(template, name); err != nil {
return err
}

fmt.Printf("\nproject successfully created in folder %s\n", name)
cmd.Printf("Template '%s' successfully copied to folder '%s'\n", template, name)

Check warning on line 37 in cmd/projects/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/create.go#L37

Added line #L37 was not covered by tests
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")

Check warning on line 43 in cmd/projects/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/create.go#L43

Added line #L43 was not covered by tests

_ = 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)

Check warning on line 51 in cmd/projects/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/create.go#L50-L51

Added lines #L50 - L51 were not covered by tests
}

func checkFolderExists(name string) error {
Expand Down
6 changes: 3 additions & 3 deletions cmd/project/list.go → cmd/projects/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package project
package projects

import (
"fmt"
Expand All @@ -9,7 +9,7 @@
func ListProjectCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List the available application node projects",
Short: "List resonate projects",

Check warning on line 12 in cmd/projects/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/list.go#L12

Added line #L12 was not covered by tests
Example: "resonate project list",
RunE: func(cmd *cobra.Command, args []string) error {
templates, err := GetProjects()
Expand All @@ -27,6 +27,6 @@

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)

Check warning on line 30 in cmd/projects/list.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/list.go#L30

Added line #L30 was not covered by tests
}
}
8 changes: 4 additions & 4 deletions cmd/project/project.go → cmd/projects/projects.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package project
package projects

import (
"encoding/json"
Expand All @@ -19,16 +19,16 @@

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "project",
Use: "projects",

Check warning on line 22 in cmd/projects/projects.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/projects.go#L22

Added line #L22 was not covered by tests
Aliases: []string{"project"},
Short: "Resonate application node projects",
Short: "Resonate projects",

Check warning on line 24 in cmd/projects/projects.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/projects.go#L24

Added line #L24 was not covered by tests
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}

// Add subcommands
cmd.AddCommand(ListProjectCmd()) // list available projects
cmd.AddCommand(ListProjectCmd()) // list projects

Check warning on line 31 in cmd/projects/projects.go

View check run for this annotation

Codecov / codecov/patch

cmd/projects/projects.go#L31

Added line #L31 was not covered by tests
cmd.AddCommand(CreateProjectCmd()) // create a project

return cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/project/scaffold.go → cmd/projects/scaffold.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package project
package projects

import (
"archive/zip"
Expand Down
12 changes: 6 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
Loading