Skip to content

Commit

Permalink
[CHANGE] Project ID as positional argument
Browse files Browse the repository at this point in the history
  • Loading branch information
eijei521 committed Aug 29, 2022
1 parent 441873e commit af21375
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/plans/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (c *Client) List() *cobra.Command {
var teamID int
var types []string
planGetCmd := &cobra.Command{
Use: `list [-t <team_id>] [--region-id <region_slug>] [--type]`,
Use: `list [-t <team_id>] [--region-id <region_slug>] [--type <type>]`,
Aliases: []string{"get"},
Short: "Retrieves list of plans details.",
Long: "Retrieves the details of plans.",
Expand Down
20 changes: 14 additions & 6 deletions internal/projects/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package projects

import (
"fmt"
"strconv"

"github.com/manifoldco/promptui"
"github.com/pkg/errors"
Expand All @@ -12,16 +13,25 @@ func (c *Client) Delete() *cobra.Command {
var projectID int
var force bool
deleteProjectCmd := &cobra.Command{
Use: `delete -p <project_id>`,
Use: `delete ID`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
prID, err := strconv.Atoi(args[0])
if err == nil {
projectID = prID
}
}
return nil
},
Short: "Delete a project.",
Long: "Deletes the specified project with a confirmation prompt. To skip the confirmation use --force.",
Example: ` # Deletes the specified project:
cherryctl project delete -p 12345
cherryctl project delete 12345
>
✔ Are you sure you want to delete project 12345: y
# Deletes a project, skipping confirmation:
cherryctl project delete -f -p 12345`,
cherryctl project delete 12345 -f`,

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
Expand All @@ -38,7 +48,7 @@ func (c *Client) Delete() *cobra.Command {
}
_, err := c.Service.Delete(projectID)
if err != nil {
return errors.Wrap(err, "Could not delete Project")
return errors.Wrap(err, "Could not delete a Project")
}

fmt.Println("Project", projectID, "successfully deleted.")
Expand All @@ -49,7 +59,5 @@ func (c *Client) Delete() *cobra.Command {
deleteProjectCmd.Flags().IntVarP(&projectID, "project-id", "p", 0, "The ID of a project.")
deleteProjectCmd.Flags().BoolVarP(&force, "force", "f", false, "Skips confirmation for the project deletion.")

_ = deleteProjectCmd.MarkFlagRequired("project-id")

return deleteProjectCmd
}
14 changes: 11 additions & 3 deletions internal/projects/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ import (
func (c *Client) Get() *cobra.Command {
var projectID int
projectGetCmd := &cobra.Command{
Use: `get [-p <project_id>]`,
Use: `get ID [-p <project_id>]`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
prID, err := strconv.Atoi(args[0])
if err == nil {
projectID = prID
}
}
return nil
},
Short: "Retrieves project details.",
Long: "Retrieves the details of the specified project.",
Example: ` # Gets the details of the specified project:
cherryctl project get -p 12345`,
cherryctl project get 12345`,

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
Expand All @@ -38,7 +47,6 @@ func (c *Client) Get() *cobra.Command {
}

projectGetCmd.Flags().IntVarP(&projectID, "project-id", "p", 0, "The project's ID.")
_ = projectGetCmd.MarkFlagRequired("project-id")

return projectGetCmd
}
15 changes: 11 additions & 4 deletions internal/projects/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ func (c *Client) Update() *cobra.Command {
name string
)
projectUpdateCmd := &cobra.Command{
Use: `update [-p <project_id>] [--name <project_name>] [--bgp <bool>]`,
Use: `update ID [-p <project_id>] [--name <project_name>] [--bgp <bool>]`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
prID, err := strconv.Atoi(args[0])
if err == nil {
projectID = prID
}
}
return nil
},
Short: "Update a project.",
Long: "Update a project.",
Example: ` # Update project to enable BGP:
cherryctl project update -p 12345 --bgp true`,
cherryctl project update 12345 --bgp true`,

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
Expand Down Expand Up @@ -49,7 +58,5 @@ func (c *Client) Update() *cobra.Command {
projectUpdateCmd.Flags().BoolVarP(&bgp, "bgp", "b", false, "True to enable BGP in a project.")
projectUpdateCmd.Flags().StringVarP(&name, "name", "", "", "Project name.")

projectUpdateCmd.MarkFlagRequired("project-id")

return projectUpdateCmd
}

0 comments on commit af21375

Please sign in to comment.