@@ -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.
@@ -140,7 +164,7 @@ module Input =
140164 | [ token ] -> MaybeParser.parseTokenValue token.Value
141165 | _ :: _ -> failwith " F# Option can only be used with a single argument."
142166 )
143- o.Arity <- ArgumentArity( 0 , 1 )
167+ o.Arity <- ArgumentArity ( 0 , 1 ) |> Arity.toArgumentArity
144168 o.DefaultValueFactory <- ( fun _ -> None)
145169 ActionInput.OfOption< 'T option> o
146170
@@ -239,10 +263,10 @@ module Input =
239263 )
240264
241265 /// Sets the arity of an option or argument.
242- let arity ( arity : ArgumentArity ) ( input : ActionInput < 'T >) =
243- input
244- |> editOption ( fun o -> o.Arity <- arity)
245- |> editArgument ( fun a -> a.Arity <- arity)
266+ let arity ( arity : Arity ) ( input : ActionInput < 'T >) =
267+ input
268+ |> editOption ( fun o -> o.Arity <- arity |> Arity.toArgumentArity )
269+ |> editArgument ( fun a -> a.Arity <- arity |> Arity.toArgumentArity )
246270
247271 /// Sets a value that indicates whether multiple arguments are allowed for each option identifier token. (Defaults to 'false'.)
248272 let allowMultipleArgumentsPerToken ( input : ActionInput < 'T >) =
0 commit comments