charmbracelet / gum

A tool for glamorous shell scripts πŸŽ€
MIT License
17.98k stars 339 forks source link

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

Open your-diary opened 1 year ago

your-diary commented 1 year ago

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

c-grimshaw commented 1 year ago

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.