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)
},
GroupID: "service",
}
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)
},
GroupID: "service",
}
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(
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())
+2 -1
View File
@@ -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'")
+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"}
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")
+2 -1
View File
@@ -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
}
+2 -1
View File
@@ -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,
+2 -1
View File
@@ -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
}
+2 -1
View File
@@ -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
}
+9 -9
View File
@@ -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
}
+2 -1
View File
@@ -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", "",
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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
}
+2 -1
View File
@@ -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")