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
+4 -1
View File
@@ -19,7 +19,10 @@ 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.
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), 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)
+11 -8
View File
@@ -14,7 +14,6 @@ import (
type stopOptions struct { type stopOptions struct {
services []string services []string
signal string signal string
timeoutChanged bool
timeout int timeout int
} }
@@ -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.
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), 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
} }
@@ -47,9 +52,7 @@ func stop(ctx context.Context, uncli *cli.CLI, opts stopOptions) error {
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 {