Skip to content

Commit

Permalink
chore(Tests): Add learning/doc test re AltCommandLine
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Feb 28, 2024
1 parent 292b98f commit 3bf9f11
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
27 changes: 13 additions & 14 deletions docs/index.fsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
(*** hide ***)
// This block of code is omitted in the generated HTML documentation. Use
// This block of code is omitted in the generated HTML documentation. Use
// it to define helpers that you do not want to show in the documentation.
#I "../src/Argu/bin/Release/netstandard2.0"
#r "Argu.dll"

open System
open Argu

type Args =
Expand Down Expand Up @@ -35,8 +34,8 @@ It can be installed using <a href="https://nuget.org/packages/Argu">NuGet</a>.
## Basic Concepts
The library is based on the simple observation that
configuration parameters can be naturally described using discriminated unions.
The library is based on the simple observation that
configuration parameters can be naturally described using discriminated unions.
For instance:
*)
Expand All @@ -49,8 +48,8 @@ type Arguments =

(**
Argu takes such discriminated unions and generates
a corresponding argument parsing scheme.
Argu takes such discriminated unions and generates
a corresponding argument parsing scheme.
For example, a parser generated from the above template would
take the following command line input
Expand Down Expand Up @@ -80,35 +79,35 @@ 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)

(**
## Who uses Argu?
* [MBrace](http://m-brace.net/)
* [FAKE](http://fsharp.github.io/FAKE/)
* [Paket](http://fsprojects.github.io/Paket/)
* [Logary](https://logary.tech)
## Documentation
* [Tutorial](tutorial.html) A short walkthrough of Argu features.
* [API Reference](reference/index.html) contains automatically generated documentation for all types,
* [API Reference](reference/index.html) contains automatically generated documentation for all types,
modules and functions in the library.
## Contributing and copyright
The project is hosted on [GitHub][gh] where you can [report issues][issues], fork
The project is hosted on [GitHub][gh] where you can [report issues][issues], fork
the project and submit pull requests.
The library is available under the MIT License.
For more information see the [License file][license] in the GitHub repository.
The library is available under the MIT License.
For more information see the [License file][license] in the GitHub repository.
[gh]: https://github.com/fsprojects/Argu
[issues]: https://github.com/fsprojects/Argu/issues
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 3bf9f11

Please sign in to comment.