From f215fae6c7b8c475f85350e7109e9b1eed056633 Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Fri, 12 Dec 2025 18:52:08 +1000 Subject: [PATCH] chore: group deploy and service management commands in uc --help --- cmd/uncloud/build.go | 1 + cmd/uncloud/deploy.go | 1 + cmd/uncloud/main.go | 21 ++++++++++++++------- cmd/uncloud/ps.go | 3 ++- cmd/uncloud/service/exec.go | 5 +++-- cmd/uncloud/service/inspect.go | 3 ++- cmd/uncloud/service/logs.go | 3 ++- cmd/uncloud/service/ls.go | 3 ++- cmd/uncloud/service/rm.go | 3 ++- cmd/uncloud/service/root.go | 18 +++++++++--------- cmd/uncloud/service/run.go | 3 ++- cmd/uncloud/service/scale.go | 3 ++- cmd/uncloud/service/start.go | 3 ++- cmd/uncloud/service/stop.go | 3 ++- 14 files changed, 46 insertions(+), 27 deletions(-) diff --git a/cmd/uncloud/build.go b/cmd/uncloud/build.go index fc9a7410..1421ab4e 100644 --- a/cmd/uncloud/build.go +++ b/cmd/uncloud/build.go @@ -49,6 +49,7 @@ to cluster machines or --push-registry to upload them to external registries.`, return runBuild(cmd.Context(), uncli, opts) }, + GroupID: "service", } cmd.Flags().StringArrayVar(&opts.BuildArgs, "build-arg", nil, diff --git a/cmd/uncloud/deploy.go b/cmd/uncloud/deploy.go index b16353b4..a044e9cb 100644 --- a/cmd/uncloud/deploy.go +++ b/cmd/uncloud/deploy.go @@ -42,6 +42,7 @@ func NewDeployCommand() *cobra.Command { return runDeploy(cmd.Context(), uncli, opts) }, + GroupID: "service", } cmd.Flags().StringArrayVar(&opts.BuildServicesOptions.BuildArgs, "build-arg", nil, diff --git a/cmd/uncloud/main.go b/cmd/uncloud/main.go index ebd07fc7..d3d84b3e 100644 --- a/cmd/uncloud/main.go +++ b/cmd/uncloud/main.go @@ -107,6 +107,11 @@ func main() { } }) + cmd.AddGroup(&cobra.Group{ + ID: "service", + Title: "Deploy and manage services:", + }) + cmd.AddCommand( NewBuildCommand(), NewDeployCommand(), @@ -119,13 +124,15 @@ func main() { image.NewRootCommand(), machine.NewRootCommand(), service.NewRootCommand(), - service.NewExecCommand(), - service.NewInspectCommand(), - service.NewListCommand(), - service.NewLogsCommand(), - service.NewRmCommand(), - service.NewRunCommand(), - service.NewScaleCommand(), + service.NewExecCommand("service"), + service.NewInspectCommand("service"), + service.NewListCommand("service"), + service.NewLogsCommand("service"), + service.NewRmCommand("service"), + service.NewRunCommand("service"), + service.NewScaleCommand("service"), + service.NewStartCommand("service"), + service.NewStopCommand("service"), volume.NewRootCommand(), ) cobra.CheckErr(cmd.Execute()) diff --git a/cmd/uncloud/ps.go b/cmd/uncloud/ps.go index c7032588..7aba1c30 100644 --- a/cmd/uncloud/ps.go +++ b/cmd/uncloud/ps.go @@ -38,7 +38,7 @@ func NewPsCommand() *cobra.Command { opts := psOptions{} cmd := &cobra.Command{ Use: "ps", - Short: "List all service containers in the cluster", + Short: "List all service containers.", Long: `List all service containers across all machines in the cluster. This command provides a comprehensive overview of all running containers that are part of a service, @@ -50,6 +50,7 @@ making it easy to see the distribution and status of containers across the clust } return runPs(cmd, opts) }, + GroupID: "service", } cmd.Flags().StringVarP(&opts.sortBy, "sort", "s", sortByService, "Sort containers by 'service', 'machine' or 'health'") diff --git a/cmd/uncloud/service/exec.go b/cmd/uncloud/service/exec.go index 98271699..ac274049 100644 --- a/cmd/uncloud/service/exec.go +++ b/cmd/uncloud/service/exec.go @@ -20,12 +20,12 @@ type execCliOptions struct { var DEFAULT_COMMAND = []string{"sh", "-c", "command -v bash >/dev/null 2>&1 && exec bash || exec sh"} -func NewExecCommand() *cobra.Command { +func NewExecCommand(groupID string) *cobra.Command { opts := execCliOptions{} execCmd := &cobra.Command{ Use: "exec [OPTIONS] SERVICE [COMMAND ARGS...]", - Short: "Execute a command in a running service container", + Short: "Execute a command in a running service container.", Long: `Execute a command (interactive shell by default) in a running container within a service. If the service has multiple replicas and no container ID is specified, the command will be executed in a random container. `, @@ -54,6 +54,7 @@ If the service has multiple replicas and no container ID is specified, the comma } return runExec(cmd.Context(), uncli, serviceName, command, opts) }, + GroupID: groupID, } execCmd.Flags().BoolVarP(&opts.detach, "detach", "d", false, "Detached mode: run command in the background") diff --git a/cmd/uncloud/service/inspect.go b/cmd/uncloud/service/inspect.go index 63c96558..5e189393 100644 --- a/cmd/uncloud/service/inspect.go +++ b/cmd/uncloud/service/inspect.go @@ -17,7 +17,7 @@ type inspectOptions struct { service string } -func NewInspectCommand() *cobra.Command { +func NewInspectCommand(groupID string) *cobra.Command { opts := inspectOptions{} cmd := &cobra.Command{ Use: "inspect SERVICE", @@ -28,6 +28,7 @@ func NewInspectCommand() *cobra.Command { opts.service = args[0] return inspect(cmd.Context(), uncli, opts) }, + GroupID: groupID, } return cmd } diff --git a/cmd/uncloud/service/logs.go b/cmd/uncloud/service/logs.go index 9ef57a93..dcc647d2 100644 --- a/cmd/uncloud/service/logs.go +++ b/cmd/uncloud/service/logs.go @@ -30,7 +30,7 @@ type logsOptions struct { machines []string } -func NewLogsCommand() *cobra.Command { +func NewLogsCommand(groupID string) *cobra.Command { var options logsOptions cmd := &cobra.Command{ @@ -68,6 +68,7 @@ If no services are specified, streams logs from all services defined in the Comp uncli := cmd.Context().Value("cli").(*cli.CLI) return runLogs(cmd.Context(), uncli, args, options) }, + GroupID: groupID, } cmd.Flags().StringSliceVar(&options.files, "file", nil, diff --git a/cmd/uncloud/service/ls.go b/cmd/uncloud/service/ls.go index ed8487f0..e32b2a2c 100644 --- a/cmd/uncloud/service/ls.go +++ b/cmd/uncloud/service/ls.go @@ -13,7 +13,7 @@ import ( "github.com/spf13/cobra" ) -func NewListCommand() *cobra.Command { +func NewListCommand(groupID string) *cobra.Command { cmd := &cobra.Command{ Use: "ls", Aliases: []string{"list"}, @@ -22,6 +22,7 @@ func NewListCommand() *cobra.Command { uncli := cmd.Context().Value("cli").(*cli.CLI) return list(cmd.Context(), uncli) }, + GroupID: groupID, } return cmd } diff --git a/cmd/uncloud/service/rm.go b/cmd/uncloud/service/rm.go index 74263807..88a4faf7 100644 --- a/cmd/uncloud/service/rm.go +++ b/cmd/uncloud/service/rm.go @@ -13,7 +13,7 @@ type rmOptions struct { services []string } -func NewRmCommand() *cobra.Command { +func NewRmCommand(groupID string) *cobra.Command { opts := rmOptions{} cmd := &cobra.Command{ Use: "rm SERVICE [SERVICE...]", @@ -30,6 +30,7 @@ directives in image Dockerfiles) are automatically removed with their containers opts.services = args return rm(cmd.Context(), uncli, opts) }, + GroupID: groupID, } return cmd } diff --git a/cmd/uncloud/service/root.go b/cmd/uncloud/service/root.go index 9b5c72d4..e33ad8ee 100644 --- a/cmd/uncloud/service/root.go +++ b/cmd/uncloud/service/root.go @@ -11,15 +11,15 @@ func NewRootCommand() *cobra.Command { Short: "Manage services in the cluster.", } cmd.AddCommand( - NewExecCommand(), - NewInspectCommand(), - NewListCommand(), - NewLogsCommand(), - NewRmCommand(), - NewRunCommand(), - NewScaleCommand(), - NewStopCommand(), - NewStartCommand(), + NewExecCommand(""), + NewInspectCommand(""), + NewListCommand(""), + NewLogsCommand(""), + NewRmCommand(""), + NewRunCommand(""), + NewScaleCommand(""), + NewStartCommand(""), + NewStopCommand(""), ) return cmd } diff --git a/cmd/uncloud/service/run.go b/cmd/uncloud/service/run.go index 45dc04af..f45258cd 100644 --- a/cmd/uncloud/service/run.go +++ b/cmd/uncloud/service/run.go @@ -36,7 +36,7 @@ type runOptions struct { volumes []string } -func NewRunCommand() *cobra.Command { +func NewRunCommand(groupID string) *cobra.Command { opts := runOptions{} cmd := &cobra.Command{ @@ -54,6 +54,7 @@ func NewRunCommand() *cobra.Command { return run(cmd.Context(), uncli, opts) }, + GroupID: groupID, } cmd.Flags().StringVar(&opts.caddyfile, "caddyfile", "", diff --git a/cmd/uncloud/service/scale.go b/cmd/uncloud/service/scale.go index a9838131..455dabd1 100644 --- a/cmd/uncloud/service/scale.go +++ b/cmd/uncloud/service/scale.go @@ -17,7 +17,7 @@ type scaleOptions struct { replicas uint } -func NewScaleCommand() *cobra.Command { +func NewScaleCommand(groupID string) *cobra.Command { opts := scaleOptions{} cmd := &cobra.Command{ Use: "scale SERVICE REPLICAS", @@ -36,6 +36,7 @@ func NewScaleCommand() *cobra.Command { return scale(cmd.Context(), uncli, opts) }, + GroupID: groupID, } return cmd diff --git a/cmd/uncloud/service/start.go b/cmd/uncloud/service/start.go index fc28d704..4a1c1121 100644 --- a/cmd/uncloud/service/start.go +++ b/cmd/uncloud/service/start.go @@ -14,7 +14,7 @@ type startOptions struct { services []string } -func NewStartCommand() *cobra.Command { +func NewStartCommand(groupID string) *cobra.Command { opts := startOptions{} cmd := &cobra.Command{ Use: "start SERVICE [SERVICE...]", @@ -26,6 +26,7 @@ func NewStartCommand() *cobra.Command { opts.services = args return start(cmd.Context(), uncli, opts) }, + GroupID: groupID, } return cmd } diff --git a/cmd/uncloud/service/stop.go b/cmd/uncloud/service/stop.go index f5a61ad5..aad49c1f 100644 --- a/cmd/uncloud/service/stop.go +++ b/cmd/uncloud/service/stop.go @@ -18,7 +18,7 @@ type stopOptions struct { timeout int } -func NewStopCommand() *cobra.Command { +func NewStopCommand(groupID string) *cobra.Command { opts := stopOptions{} cmd := &cobra.Command{ Use: "stop SERVICE [SERVICE...]", @@ -31,6 +31,7 @@ func NewStopCommand() *cobra.Command { opts.timeoutChanged = cmd.Flags().Changed("timeout") return stop(cmd.Context(), uncli, opts) }, + GroupID: groupID, } cmd.Flags().StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container") cmd.Flags().IntVarP(&opts.timeout, "timeout", "t", 0, "Seconds to wait before killing the container")