@@ -44,6 +44,30 @@ type ActionInput<'T>(inputType: ActionInputSource) =
4444 | ParsedArgument a -> a :?> Argument< 'T> |> parseResult.GetValue
4545 | Context -> parseResult |> unbox< 'T>
4646
47+ type Arity =
48+ | ArgumentArity of min : int * max : int
49+ | ExactlyOne
50+ | MaximumNumberOfValues of max : int
51+ | MinimumNumberOfValues of min : int
52+ | OneOrMore
53+ | Zero
54+ | ZeroOrMore
55+ | ZeroOrOne
56+
57+ module Arity =
58+
59+ let toArgumentArity ( arity : Arity ) =
60+ match arity with
61+ | ArgumentArity ( min, max) -> ( min, max)
62+ | ExactlyOne -> ( 1 , 1 )
63+ | MaximumNumberOfValues max -> ( 0 , max)
64+ | MinimumNumberOfValues min -> ( min, 100_000 )
65+ | OneOrMore -> ( 1 , 100_000 )
66+ | Zero -> ( 0 , 0 )
67+ | ZeroOrMore -> ( 0 , 100_000 )
68+ | ZeroOrOne -> ( 0 , 1 )
69+ |> System.CommandLine.ArgumentArity
70+
4771module Input =
4872
4973 /// Injects an ` ActionContext ` into the action which contains the ` ParseResult ` and a cancellation token.
@@ -134,7 +158,7 @@ module Input =
134158 | [ token ] -> MaybeParser.parseTokenValue token.Value
135159 | _ :: _ -> failwith " F# Option can only be used with a single argument."
136160 )
137- o.Arity <- ArgumentArity( 0 , 1 )
161+ o.Arity <- ArgumentArity ( 0 , 1 ) |> Arity.toArgumentArity
138162 o.DefaultValueFactory <- ( fun _ -> None)
139163 ActionInput.OfOption< 'T option> o
140164
@@ -233,10 +257,10 @@ module Input =
233257 )
234258
235259 /// Sets the arity of an option or argument.
236- let arity ( arity : ArgumentArity ) ( input : ActionInput < 'T >) =
237- input
238- |> editOption ( fun o -> o.Arity <- arity)
239- |> editArgument ( fun a -> a.Arity <- arity)
260+ let arity ( arity : Arity ) ( input : ActionInput < 'T >) =
261+ input
262+ |> editOption ( fun o -> o.Arity <- arity |> Arity.toArgumentArity )
263+ |> editArgument ( fun a -> a.Arity <- arity |> Arity.toArgumentArity )
240264
241265 /// Sets a value that indicates whether multiple arguments are allowed for each option identifier token. (Defaults to 'false'.)
242266 let allowMultipleArgumentsPerToken ( input : ActionInput < 'T >) =
0 commit comments