gum icon indicating copy to clipboard operation
gum copied to clipboard

Add a sensible default unit for `--timeout` option.

Open your-diary opened this issue 2 years ago β€’ 1 comments

Is your feature request related to a problem? Please describe. Currently, you always have to specify the unit of timeout in --timeout like --timeout 10s. Personally, this seems verbose in some cases.

Describe the solution you'd like

  • It would be great if the unit falls back to a sensible default (e.g. second) when it is not explicitly specified, making --timeout 10 and --timeout 10s the same. In many UNIX programs (e.g. curl, ping, etc.), the default unit is second.

  • Or, at least, we may want to explicitly states there should be a unit in the help page. The current description is

    --timeout=0     Timeout until input aborts ($GUM_INPUT_TIMEOUT)
    

your-diary avatar Jul 22 '23 06:07 your-diary

I believe this default behaviour is powered by kong, the CLI tooling powering gum, during parsing. In turn, that dependency defaults to using time.ParseDuration from the standard library, which does not support unit-less conversions without returning an error.

However, we can probably override this behaviour by implementing the MapperValue interface for the timeout field, still using time.ParseDuration, but handling the "missing unit" case whenever a unit is... Missing πŸ˜Άβ€πŸŒ«οΈ.

Unfortunately, that "missing unit" error is not exported from time, so I feel the switch statement might be a bit weird (...string.Contains?). Furthermore, it would probably require swapping out the timeout behaviours for all the CLI Options, not just input/options.go, for a homogenous interface.

c-grimshaw avatar Jul 23 '23 20:07 c-grimshaw