cmdliner icon indicating copy to clipboard operation
cmdliner copied to clipboard

Enable creation of shortcircuiting options, like `--help` and `--version`

Open rand00 opened this issue 3 years ago • 3 comments
trafficstars

I just were in a situation where I wanted to create an alternative shortcircuiting option, lets call it --version-of-foo. From the interface there doesn't seem to be an elegant solution. Arguments for enabling this:

  • My guess is that it can be a pretty common thing to want
  • Feels weird to not be able to build the semantics that Cmdliner exposes via --help and --version

rand00 avatar Apr 28 '22 15:04 rand00

There are certainly many different workarounds (e.g. process your Sys.argv before giving it to Cmdliner) and I don't have the feeling that's a "pretty common thing to want".

I'm not sure I want to add more complexity to Cmdliner's API for these niche usages.

dbuenzli avatar Apr 28 '22 15:04 dbuenzli

I havn't dived into the implementation, but looking at the interface - might it be possible to make a function in inspired by Arg.required?:

val shortcircuiting : 'a option t -> 'a Term.t

Where, when option term evaluates to Some _, would shortcircuit, and otherwise not. This would not bring much complexity - but the question is if the underlying state easily supports this semantics.

rand00 avatar Apr 29 '22 07:04 rand00

... shortcircuiting getting a thunk to run as well

rand00 avatar Apr 29 '22 07:04 rand00

Not convinced by the need. Closing for now.

dbuenzli avatar Jan 13 '23 00:01 dbuenzli