Closed njlr closed 2 years ago
Does AltCommandLine
as illustrated in https://fsprojects.github.io/Argu/tutorial.html#SubCommands fit the bill ?
I dug into the source-code and found CustomCommandLineAttribute
, which is exactly what I was looking for!
#r "nuget: Argu, 6.1.1"
open Argu
type CLIArgument =
| [<CustomCommandLine("--working-directory")>] WorkingDirectory of path : string
interface IArgParserTemplate with
member this.Usage =
match this with
| WorkingDirectory _ -> "Set the working directory"
let parser = ArgumentParser.Create<CLIArgument>(programName = "gadget.exe")
// ---------------
let examples =
[
[||]
[| "--help" |]
[| "--working-directory"; "a/b/c" |]
]
for example in examples do
printfn "%A" example
let pr = parser.Parse(example, raiseOnUsage = false)
if pr.IsUsageRequested then
printfn "%A" <| parser.PrintUsage()
else
printfn "%A" <| pr.GetAllResults()
printfn "------"
Argu suggest declaring options like this:
But that does not agree with my linter.
Can I specify options like this:
And then tell Argu how to generate the names, for example using an annotation or even explicit names?
Explicit names via a static function:
Or via a parameter: