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{
Use: "start SERVICE [SERVICE...]",
Short: "Start one or more services.",
Long: "Start one or more services.",
Args: cobra.MinimumNArgs(1),
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),
RunE: func(cmd *cobra.Command, args []string) error {
uncli := cmd.Context().Value("cli").(*cli.CLI)
opts.services = args
+16 -13
View File
@@ -12,10 +12,9 @@ import (
)
type stopOptions struct {
services []string
signal string
timeoutChanged bool
timeout int
services []string
signal string
timeout int
}
func NewStopCommand(groupID string) *cobra.Command {
@@ -23,18 +22,24 @@ func NewStopCommand(groupID string) *cobra.Command {
cmd := &cobra.Command{
Use: "stop SERVICE [SERVICE...]",
Short: "Stop one or more services.",
Long: "Stop one or more services.",
Args: cobra.MinimumNArgs(1),
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),
RunE: func(cmd *cobra.Command, args []string) error {
uncli := cmd.Context().Value("cli").(*cli.CLI)
opts.services = args
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")
cmd.Flags().StringVarP(&opts.signal, "signal", "s", "",
"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
}
@@ -46,10 +51,8 @@ func stop(ctx context.Context, uncli *cli.CLI, opts stopOptions) error {
defer client.Close()
stopOpts := container.StopOptions{
Signal: opts.signal,
}
if opts.timeoutChanged {
stopOpts.Timeout = &opts.timeout
Signal: opts.signal,
Timeout: &opts.timeout,
}
for _, s := range opts.services {