fsprojects / Argu

A declarative CLI argument parser for F#
https://fsprojects.github.io/Argu
MIT License
453 stars 75 forks source link

Feature idea - Helper function for subcommand field #165

Closed dgounaris closed 2 years ago

dgounaris commented 3 years ago

Description

Currently, to get a field from a potential subcommand one has to write the following boilerplate piece of code

match parseResults.TryGetSubCommand() with
  | Some (SC_a args) -> args.GetResult SC_a_field
  | _ -> None

In my case, I am populating an internal configuration object from cli fields where a lot of them are subcommand ones, making such match cases ugly duplicates.

Expected behavior

I believe it would be useful to have a function which (using reflective ways) can get inner subcommand fields type-safely. Seems like an intuitive api addition to me.

Actual behavior

One has to write a match expression as described above.

Known workarounds

A function such as: TryGetResultFromSubCommand : parseResults: ParseResults<'TopLevelArgs> -> scType: (ParseResults<'SCArgs> -> 'TopLevelArgs) -> innerOption:Expr<('Field -> 'SCArgs)> -> 'Field option can be created and used conveniently for such queries, enforcing proper types