chore: group deploy and service management commands in uc --help

This commit is contained in:
Pasha Sviderski
2025-12-12 18:52:08 +10:00
parent 5707c37b63
commit f215fae6c7
14 changed files with 46 additions and 27 deletions
+1
View File
@@ -49,6 +49,7 @@ to cluster machines or --push-registry to upload them to external registries.`,
return runBuild(cmd.Context(), uncli, opts) return runBuild(cmd.Context(), uncli, opts)
}, },
GroupID: "service",
} }
cmd.Flags().StringArrayVar(&opts.BuildArgs, "build-arg", nil, cmd.Flags().StringArrayVar(&opts.BuildArgs, "build-arg", nil,
+1
View File
@@ -42,6 +42,7 @@ func NewDeployCommand() *cobra.Command {
return runDeploy(cmd.Context(), uncli, opts) return runDeploy(cmd.Context(), uncli, opts)
}, },
GroupID: "service",
} }
cmd.Flags().StringArrayVar(&opts.BuildServicesOptions.BuildArgs, "build-arg", nil, cmd.Flags().StringArrayVar(&opts.BuildServicesOptions.BuildArgs, "build-arg", nil,
+14 -7
View File
@@ -107,6 +107,11 @@ func main() {
} }
}) })
cmd.AddGroup(&cobra.Group{
ID: "service",
Title: "Deploy and manage services:",
})
cmd.AddCommand( cmd.AddCommand(
NewBuildCommand(), NewBuildCommand(),
NewDeployCommand(), NewDeployCommand(),
@@ -119,13 +124,15 @@ func main() {
image.NewRootCommand(), image.NewRootCommand(),
machine.NewRootCommand(), machine.NewRootCommand(),
service.NewRootCommand(), service.NewRootCommand(),
service.NewExecCommand(), service.NewExecCommand("service"),
service.NewInspectCommand(), service.NewInspectCommand("service"),
service.NewListCommand(), service.NewListCommand("service"),
service.NewLogsCommand(), service.NewLogsCommand("service"),
service.NewRmCommand(), service.NewRmCommand("service"),
service.NewRunCommand(), service.NewRunCommand("service"),
service.NewScaleCommand(), service.NewScaleCommand("service"),
service.NewStartCommand("service"),
service.NewStopCommand("service"),
volume.NewRootCommand(), volume.NewRootCommand(),
) )
cobra.CheckErr(cmd.Execute()) cobra.CheckErr(cmd.Execute())
+2 -1
View File
@@ -38,7 +38,7 @@ func NewPsCommand() *cobra.Command {
opts := psOptions{} opts := psOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ps", 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. 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, 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) return runPs(cmd, opts)
}, },
GroupID: "service",
} }
cmd.Flags().StringVarP(&opts.sortBy, "sort", "s", sortByService, cmd.Flags().StringVarP(&opts.sortBy, "sort", "s", sortByService,
"Sort containers by 'service', 'machine' or 'health'") "Sort containers by 'service', 'machine' or 'health'")
+3 -2
View File
@@ -20,12 +20,12 @@ type execCliOptions struct {
var DEFAULT_COMMAND = []string{"sh", "-c", "command -v bash >/dev/null 2>&1 && exec bash || exec sh"} 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{} opts := execCliOptions{}
execCmd := &cobra.Command{ execCmd := &cobra.Command{
Use: "exec [OPTIONS] SERVICE [COMMAND ARGS...]", 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. 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. 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) 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") execCmd.Flags().BoolVarP(&opts.detach, "detach", "d", false, "Detached mode: run command in the background")
+2 -1
View File
@@ -17,7 +17,7 @@ type inspectOptions struct {
service string service string
} }
func NewInspectCommand() *cobra.Command { func NewInspectCommand(groupID string) *cobra.Command {
opts := inspectOptions{} opts := inspectOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "inspect SERVICE", Use: "inspect SERVICE",
@@ -28,6 +28,7 @@ func NewInspectCommand() *cobra.Command {
opts.service = args[0] opts.service = args[0]
return inspect(cmd.Context(), uncli, opts) return inspect(cmd.Context(), uncli, opts)
}, },
GroupID: groupID,
} }
return cmd return cmd
} }
+2 -1
View File
@@ -30,7 +30,7 @@ type logsOptions struct {
machines []string machines []string
} }
func NewLogsCommand() *cobra.Command { func NewLogsCommand(groupID string) *cobra.Command {
var options logsOptions var options logsOptions
cmd := &cobra.Command{ 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) uncli := cmd.Context().Value("cli").(*cli.CLI)
return runLogs(cmd.Context(), uncli, args, options) return runLogs(cmd.Context(), uncli, args, options)
}, },
GroupID: groupID,
} }
cmd.Flags().StringSliceVar(&options.files, "file", nil, cmd.Flags().StringSliceVar(&options.files, "file", nil,
+2 -1
View File
@@ -13,7 +13,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func NewListCommand() *cobra.Command { func NewListCommand(groupID string) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ls", Use: "ls",
Aliases: []string{"list"}, Aliases: []string{"list"},
@@ -22,6 +22,7 @@ func NewListCommand() *cobra.Command {
uncli := cmd.Context().Value("cli").(*cli.CLI) uncli := cmd.Context().Value("cli").(*cli.CLI)
return list(cmd.Context(), uncli) return list(cmd.Context(), uncli)
}, },
GroupID: groupID,
} }
return cmd return cmd
} }
+2 -1
View File
@@ -13,7 +13,7 @@ type rmOptions struct {
services []string services []string
} }
func NewRmCommand() *cobra.Command { func NewRmCommand(groupID string) *cobra.Command {
opts := rmOptions{} opts := rmOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "rm SERVICE [SERVICE...]", Use: "rm SERVICE [SERVICE...]",
@@ -30,6 +30,7 @@ directives in image Dockerfiles) are automatically removed with their containers
opts.services = args opts.services = args
return rm(cmd.Context(), uncli, opts) return rm(cmd.Context(), uncli, opts)
}, },
GroupID: groupID,
} }
return cmd return cmd
} }
+9 -9
View File
@@ -11,15 +11,15 @@ func NewRootCommand() *cobra.Command {
Short: "Manage services in the cluster.", Short: "Manage services in the cluster.",
} }
cmd.AddCommand( cmd.AddCommand(
NewExecCommand(), NewExecCommand(""),
NewInspectCommand(), NewInspectCommand(""),
NewListCommand(), NewListCommand(""),
NewLogsCommand(), NewLogsCommand(""),
NewRmCommand(), NewRmCommand(""),
NewRunCommand(), NewRunCommand(""),
NewScaleCommand(), NewScaleCommand(""),
NewStopCommand(), NewStartCommand(""),
NewStartCommand(), NewStopCommand(""),
) )
return cmd return cmd
} }
+2 -1
View File
@@ -36,7 +36,7 @@ type runOptions struct {
volumes []string volumes []string
} }
func NewRunCommand() *cobra.Command { func NewRunCommand(groupID string) *cobra.Command {
opts := runOptions{} opts := runOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
@@ -54,6 +54,7 @@ func NewRunCommand() *cobra.Command {
return run(cmd.Context(), uncli, opts) return run(cmd.Context(), uncli, opts)
}, },
GroupID: groupID,
} }
cmd.Flags().StringVar(&opts.caddyfile, "caddyfile", "", cmd.Flags().StringVar(&opts.caddyfile, "caddyfile", "",
+2 -1
View File
@@ -17,7 +17,7 @@ type scaleOptions struct {
replicas uint replicas uint
} }
func NewScaleCommand() *cobra.Command { func NewScaleCommand(groupID string) *cobra.Command {
opts := scaleOptions{} opts := scaleOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "scale SERVICE REPLICAS", Use: "scale SERVICE REPLICAS",
@@ -36,6 +36,7 @@ func NewScaleCommand() *cobra.Command {
return scale(cmd.Context(), uncli, opts) return scale(cmd.Context(), uncli, opts)
}, },
GroupID: groupID,
} }
return cmd return cmd
+2 -1
View File
@@ -14,7 +14,7 @@ type startOptions struct {
services []string services []string
} }
func NewStartCommand() *cobra.Command { func NewStartCommand(groupID string) *cobra.Command {
opts := startOptions{} opts := startOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "start SERVICE [SERVICE...]", Use: "start SERVICE [SERVICE...]",
@@ -26,6 +26,7 @@ func NewStartCommand() *cobra.Command {
opts.services = args opts.services = args
return start(cmd.Context(), uncli, opts) return start(cmd.Context(), uncli, opts)
}, },
GroupID: groupID,
} }
return cmd return cmd
} }
+2 -1
View File
@@ -18,7 +18,7 @@ type stopOptions struct {
timeout int timeout int
} }
func NewStopCommand() *cobra.Command { func NewStopCommand(groupID string) *cobra.Command {
opts := stopOptions{} opts := stopOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "stop SERVICE [SERVICE...]", Use: "stop SERVICE [SERVICE...]",
@@ -31,6 +31,7 @@ func NewStopCommand() *cobra.Command {
opts.timeoutChanged = cmd.Flags().Changed("timeout") opts.timeoutChanged = cmd.Flags().Changed("timeout")
return stop(cmd.Context(), uncli, opts) return stop(cmd.Context(), uncli, opts)
}, },
GroupID: groupID,
} }
cmd.Flags().StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container") 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") cmd.Flags().IntVarP(&opts.timeout, "timeout", "t", 0, "Seconds to wait before killing the container")