cmdliner icon indicating copy to clipboard operation
cmdliner copied to clipboard

Supporting single-dashed long options for legacy tools

Open Halbaroth opened this issue 7 months ago • 0 comments

Cmdliner determines the option format based on the length of the option name:

  • For options of length 1, it uses a single dash (e.g., -f).
  • For options longer than one character, it uses a double dash (e.g., --foo).

It is a reasonable standard to enforce, but single-dashed long options (e.g., -foo) are still common in some legacy tools within the OCaml ecosystem. Replacing Args with Cmdliner in such tools can break existing cli.

I suggest to expose a more general constructor for argument names:

type name = 
| Simple_dash of string
| Double_dash of string

val make :
  ?deprecated:string -> 
  ?absent:string -> 
  ?docs:string -> 
  ?docv:string ->
  ?doc:string -> 
  ?env:Env.info -> 
  name list -> 
  t

With this constructor, a legacy option like -foo could be supported alongside modern alternatives such as -f and --foo.

Halbaroth avatar May 12 '25 09:05 Halbaroth