File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -796,7 +796,7 @@ type Configuration =
796796 | Release
797797
798798let config =
799- Input.option<Configuration>
799+ Input.option<Configuration> "--config"
800800 |> Input.mapFromAmong [
801801 "r", Release; "release", Release
802802 "R", Release; "Release", Release
@@ -808,16 +808,13 @@ let config =
808808// use `Input.mapFromAmongWith` to pass a custom string comparer!
809809
810810let config =
811- Input.option<Configuration>
811+ Input.option<Configuration> "--config"
812812 |> Input.mapFromAmongWith StringComparer.OrdinalIgnoreCase [
813813 "r", Release; "release", Release
814814 "d", Debug; "debug", Debug
815815 ]
816816```
817817
818- Notes about overriding properties:
819- * ` Input.tryParse ` will overwrite the configuration from ` .mapFromAmong ` if it is used downstream.
820-
821818</details >
822819
823820---
Original file line number Diff line number Diff line change 1- namespace FSharp.SystemCommandLine
1+ namespace FSharp.SystemCommandLine
22
33open System
44open System.CommandLine
@@ -309,10 +309,8 @@ module Input =
309309 )
310310
311311
312- /// <summary >
313- /// Maps an input whose legal values are a known set bound to a typed value using the given <c >StringComparer</c >.
314- /// <remarks >Caution: avoid overriding downstream with <c >Input.tryParse</c >.</remarks >
315- /// </summary >
312+ /// Maps an input whose legal values are a known set of strings, each bound to a typed value, using the given ` StringComparer ` .
313+ /// Example: ` option<Env> "--env" |> mapFromAmongWith StringComparer.OrdinalIgnoreCase [ "dev", Dev; "prod", Prod ] `
316314 let mapFromAmongWith ( comparer : StringComparer ) ( choices : seq < string * 'T >) ( input : ActionInput < 'T >) =
317315 let keys = choices |> Seq.map fst
318316 let legal = keys |> String.concat " , "
@@ -329,8 +327,8 @@ module Input =
329327 | None -> Error $" '%s {token.Value}' is not a valid choice from: %s {legal}"
330328 )
331329
332- /// < summary > Maps an input whose legal values are a known set bound to a typed value.</ summary >
333- /// < remarks >Caution: avoid overriding downstream with < c >Input.tryParse</ c >.</ remarks >
330+ /// Maps an input whose legal values are a known set of strings, each bound to a typed value (case-sensitive).
331+ /// Example: ` option<Env> "--env" |> mapFromAmong [ "dev", Dev; "prod", Prod ] `
334332 let mapFromAmong ( choices : seq < string * 'T >) ( input : ActionInput < 'T >) =
335333 mapFromAmongWith StringComparer.Ordinal choices input
336334
Original file line number Diff line number Diff line change @@ -93,35 +93,3 @@ let ``03 - mapFromAmongWith returns correct typed DU - case insensitive``() =
9393 // invalid map
9494 shouldFail " --du a" B
9595 shouldFail " --du B" A
96-
97- [<Test>]
98- let ``04 - mapFromAmong followed by different tryParse will override`` () =
99- let input = option< DUType> " --du" |> mapFromAmong duChoices |> tryParse ( fun _ -> Ok A)
100- let compareAgainst ( shouldSucceed : bool ): string -> DUType -> unit = fun cmd v ->
101- testRootCommand cmd {
102- description " Test"
103- inputs input
104- setAction ( fun o ->
105- if shouldSucceed
106- then o =! v |> callAction; 0
107- else o <>! v; 1
108- )
109- }
110- |> if shouldSucceed then (=!) 0 else (<>!) 0
111- actionCalled =! shouldSucceed
112- actionCalled <- false
113- let shouldSucceed = compareAgainst true
114- let shouldFail = compareAgainst false
115- shouldSucceed " --du a" A
116- shouldSucceed " --du A" A
117- shouldSucceed " --du b" A
118- shouldSucceed " --du B" A
119- shouldFail " --du a" B
120- shouldFail " --du A" B
121- shouldFail " --du b" B
122- shouldFail " --du B" B
123- // invalid input still processes
124- // completions will still show correctly
125- // undefined behaviour
126- shouldSucceed " --du c" A
127- shouldFail " --du c" B
You can’t perform that action at this time.
0 commit comments