chore: 'uc stop' - make --timeout default explicit, update flag and long descriptions

This commit is contained in:
Pasha Sviderski
2025-12-12 19:16:17 +10:00
parent f215fae6c7
commit 596bc561b8
2 changed files with 21 additions and 15 deletions
+5 -2
View File
@@ -19,8 +19,11 @@ func NewStartCommand(groupID string) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "start SERVICE [SERVICE...]", Use: "start SERVICE [SERVICE...]",
Short: "Start one or more services.", Short: "Start one or more services.",
Long: "Start one or more services.", Long: `Start one or more previously stopped services.
Args: cobra.MinimumNArgs(1),
Starts all containers of the specified service(s) across all machines in the cluster.
Services can be specified by name or ID.`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
uncli := cmd.Context().Value("cli").(*cli.CLI) uncli := cmd.Context().Value("cli").(*cli.CLI)
opts.services = args opts.services = args
+16 -13
View File
@@ -12,10 +12,9 @@ import (
) )
type stopOptions struct { type stopOptions struct {
services []string services []string
signal string signal string
timeoutChanged bool timeout int
timeout int
} }
func NewStopCommand(groupID string) *cobra.Command { func NewStopCommand(groupID string) *cobra.Command {
@@ -23,18 +22,24 @@ func NewStopCommand(groupID string) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "stop SERVICE [SERVICE...]", Use: "stop SERVICE [SERVICE...]",
Short: "Stop one or more services.", Short: "Stop one or more services.",
Long: "Stop one or more services.", Long: `Stop one or more running services.
Args: cobra.MinimumNArgs(1),
Gracefully stops all containers of the specified service(s) across all machines in the cluster.
Services can be specified by name or ID. Stopped services can be restarted with 'uc start'.`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
uncli := cmd.Context().Value("cli").(*cli.CLI) uncli := cmd.Context().Value("cli").(*cli.CLI)
opts.services = args opts.services = args
opts.timeoutChanged = cmd.Flags().Changed("timeout")
return stop(cmd.Context(), uncli, opts) return stop(cmd.Context(), uncli, opts)
}, },
GroupID: groupID, GroupID: groupID,
} }
cmd.Flags().StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container") cmd.Flags().StringVarP(&opts.signal, "signal", "s", "",
cmd.Flags().IntVarP(&opts.timeout, "timeout", "t", 0, "Seconds to wait before killing the container") "Signal to send to each container's main process.\n"+
"Can be a signal name (SIGTERM, SIGINT, SIGHUP, etc.) or a number. (default SIGTERM)")
cmd.Flags().IntVarP(&opts.timeout, "timeout", "t", 10,
"Seconds to wait for each container to stop gracefully before forcibly killing it with SIGKILL.\n"+
"Use -1 to wait indefinitely.")
return cmd return cmd
} }
@@ -46,10 +51,8 @@ func stop(ctx context.Context, uncli *cli.CLI, opts stopOptions) error {
defer client.Close() defer client.Close()
stopOpts := container.StopOptions{ stopOpts := container.StopOptions{
Signal: opts.signal, Signal: opts.signal,
} Timeout: &opts.timeout,
if opts.timeoutChanged {
stopOpts.Timeout = &opts.timeout
} }
for _, s := range opts.services { for _, s := range opts.services {