Skip to content

Commit

Permalink
feat: group commands into user vs internal vs additional
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Mitchell <[email protected]>
  • Loading branch information
starpit committed Sep 26, 2024
1 parent 1a3cc57 commit ef34ca5
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 28 deletions.
9 changes: 5 additions & 4 deletions cmd/subcommands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ func newBuildCmd() *cobra.Command {
var allFlag bool

cmd := &cobra.Command{
Use: "build [path-or-git]",
Short: "Generate a binary specialized to a given application",
Long: "Generate a binary specialized to a given application",
Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs),
Use: "build [path-or-git]",
GroupID: applicationGroup.ID,
Short: "Generate a binary specialized to a given application",
Long: "Generate a binary specialized to a given application",
Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs),
}

cmd.Flags().StringVarP(&outputFlag, "output", "o", "", "Path to store output binary")
Expand Down
5 changes: 3 additions & 2 deletions cmd/subcommands/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

func init() {
cmd := &cobra.Command{
Use: "component",
Short: "Commands related to specific components",
Use: "component",
GroupID: internalGroup.ID,
Short: "Commands related to specific components",
}
rootCmd.AddCommand(cmd)

Expand Down
7 changes: 4 additions & 3 deletions cmd/subcommands/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (

func init() {
var cmd = &cobra.Command{
Use: "dev",
Short: "Commands related to local Lunchpail development",
Long: "Commands related to local Lunchpail development",
Use: "dev",
GroupID: internalGroup.ID,
Short: "Commands related to local Lunchpail development",
Long: "Commands related to local Lunchpail development",
}

cmd.AddCommand(dev.Init())
Expand Down
7 changes: 4 additions & 3 deletions cmd/subcommands/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ func newDownCmd() *cobra.Command {
var deleteCloudResourcesFlag bool

var cmd = &cobra.Command{
Use: "down [run1] [run2] ...",
Short: "Undeploy the application",
Long: "Undeploy the application",
Use: "down [run1] [run2] ...",
GroupID: runGroup.ID,
Short: "Undeploy a run",
Long: "Undeploy a run",
}

cmd.Flags().BoolVarP(&deleteNamespaceFlag, "delete-namespace", "N", false, "Also delete namespace (only for empty namespaces)")
Expand Down
5 changes: 3 additions & 2 deletions cmd/subcommands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

func newInfoCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "info",
Short: "Summary information of the application",
Use: "info",
GroupID: applicationGroup.ID,
Short: "Summary information of the application",
RunE: func(cmd *cobra.Command, args []string) error {
return info.UI()
},
Expand Down
9 changes: 5 additions & 4 deletions cmd/subcommands/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ func newLogsCommand() *cobra.Command {
var tailFlag int

var cmd = &cobra.Command{
Use: "logs",
Short: "Print or stream logs from the application",
Long: "Print or stream logs from the application",
Args: cobra.MatchAll(cobra.ExactArgs(0), cobra.OnlyValidArgs),
Use: "logs",
GroupID: runGroup.ID,
Short: "Print or stream logs from a run",
Long: "Print or stream logs from a run",
Args: cobra.MatchAll(cobra.ExactArgs(0), cobra.OnlyValidArgs),
}

cmd.Flags().StringSliceVarP(&componentsFlag, "component", "c", []string{"workers"}, "Components to track (workers|dispatcher|workstealer|minio)")
Expand Down
5 changes: 3 additions & 2 deletions cmd/subcommands/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

func init() {
cmd := &cobra.Command{
Use: "queue",
Short: "Commands related to the queue",
Use: "queue",
GroupID: internalGroup.ID,
Short: "Commands related to the queue",
}
rootCmd.AddCommand(cmd)

Expand Down
5 changes: 3 additions & 2 deletions cmd/subcommands/queue_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (

func init() {
cmd := &cobra.Command{
Use: "queue",
Short: "Commands related to the queue",
Use: "queue",
GroupID: internalGroup.ID,
Short: "Commands related to the queue",
}
rootCmd.AddCommand(cmd)

Expand Down
11 changes: 11 additions & 0 deletions cmd/subcommands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/spf13/cobra"

"lunchpail.io/pkg/build"
)

Expand All @@ -12,6 +13,10 @@ var rootCmd = &cobra.Command{
Use: "lunchpail",
}

var applicationGroup = &cobra.Group{ID: "Application", Title: "Application Commands"}
var runGroup = &cobra.Group{ID: "Run", Title: "Run Commands"}
var internalGroup = &cobra.Group{ID: "Internal", Title: "Advanced/Internal Commands"}

func Execute() error {
if build.IsBuilt() {
rootCmd.Use = build.Name()
Expand All @@ -25,6 +30,12 @@ func Execute() error {
}

func init() {
rootCmd.AddGroup(applicationGroup)
if build.IsBuilt() {
rootCmd.AddGroup(runGroup)
}
rootCmd.AddGroup(internalGroup)

// To tell Cobra to mark the default completion command as
// hidden (see
// https://github.com/spf13/cobra/blob/main/site/content/completions/_index.md#adapting-the-default-completion-command)
Expand Down
5 changes: 3 additions & 2 deletions cmd/subcommands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
func init() {
if build.IsBuilt() {
cmd := &cobra.Command{
Use: "status",
Short: "Commands related to run status",
Use: "status",
GroupID: runGroup.ID,
Short: "Commands related to the status of a run",
}

rootCmd.AddCommand(cmd)
Expand Down
9 changes: 5 additions & 4 deletions cmd/subcommands/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ func newUpCmd() *cobra.Command {
var createCluster bool

var cmd = &cobra.Command{
Use: "up [inputFilesOrDirectories...]",
Short: "Deploy the application",
Long: "Deploy the application",
Args: cobra.MatchAll(cobra.OnlyValidArgs),
Use: "up [inputFilesOrDirectories...]",
GroupID: applicationGroup.ID,
Short: "Deploy the application",
Long: "Deploy the application",
Args: cobra.MatchAll(cobra.OnlyValidArgs),
}

if util.StdoutIsTty() {
Expand Down

0 comments on commit ef34ca5

Please sign in to comment.