Skip to content

Commit

Permalink
chore(Tests): Add learning/doc test re AltCommandLine (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink authored Feb 28, 2024
1 parent 6b60199 commit 40e0e26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/index.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Furthermore, you can parse environment variables, by supplying the an `Environme

let argv = [| "--log-level"; "3" |]
let reader = EnvironmentVariableConfigurationReader() :> IConfigurationReader
let parser = ArgumentParser.Create<Args>(programName = "rutta")
let parser = ArgumentParser.Create<Args>(programName = "rutta")
// pass the reader to the Parse call
let results = parser.Parse(argv, configurationReader = reader)

Expand Down
25 changes: 25 additions & 0 deletions tests/Argu.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,31 @@ module ``Argu Tests Main List`` =
raisesWith<ArguException> <@ ArgumentParser.Create<GenericArgument<string>>() @>
(fun e -> <@ e.FirstLine.Contains "generic" @>)

type NestedDuplicatesAreOk =
| [<AltCommandLine("-f")>] Force
| [<AltCommandLine("-N"); CliPrefix(CliPrefix.None)>] Nested of ParseResults<NestedSimilar>
interface IArgParserTemplate with
member _.Usage = "not tested"
and NestedSimilar =
| [<AltCommandLine("-f")>] Force
interface IArgParserTemplate with
member this.Usage = "clean"

// repro attempt for confusing "ERROR: unrecognized argument:" messages
// Actual solution: replace `dotnet toolname commandline -d ` with `dotnet tool run toolname commandline -d`
// (The `-d` was being interpreted as a switch for the `dotnet` exe)
// see https://github.com/dotnet/sdk/issues/14626
let aliases = [|
[| "-f" ; "nested" ; "--force" |]
[| "--force" ; "nested" ; "--force" |]
[| "-f" ; "nested" ; "-f" |]
[| "-f" ; "-N" ; "-f" |] |] |> Seq.map Array.singleton
[<Theory; MemberData(nameof aliases)>]
let ``Nested aliased names are fine`` (args: string[]) =
let results = ArgumentParser.Create<NestedDuplicatesAreOk>().ParseCommandLine args
test <@ results.Contains NestedDuplicatesAreOk.Force @>
let nested = results.GetResult Nested
test <@ nested.Contains Force @>

[<CliPrefix(CliPrefix.Dash)>]
type ArgumentSingleDash =
Expand Down

0 comments on commit 40e0e26

Please sign in to comment.