@@ -16,22 +16,10 @@ let private parseInput<'V> (handlerInput: ActionInput) (pr: ParseResult) (cancel
1616 | ParsedArgument a -> pr.GetValue< 'V>( a :?> Argument< 'V>)
1717 | Context -> { ParseResult = pr; CancellationToken = cancelToken } |> unbox< 'V>
1818
19- /// Adds global options to a command, ensuring they are recursive.
20- let private addGlobalOptionsToCommand ( globalOptions : ActionInput list ) ( cmd : Command ) =
21- for g in globalOptions do
22- match g.Source with
23- | ParsedOption o ->
24- o.Recursive <- true // Ensure global options are recursive
25- cmd.Add( o)
26- | ParsedArgument _ -> () // cmd.Add(a) // TODO: Should arguments be added globally?
27- | Context -> ()
28- cmd
29-
3019type CommandSpec < 'Inputs , 'Output > =
3120 {
3221 Description: string
3322 Inputs: ActionInput list
34- GlobalInputs: ActionInput list
3523 Handler: 'Inputs -> 'Output
3624 Aliases: string list
3725 SubCommands: System .CommandLine .Command list
@@ -43,7 +31,6 @@ type CommandSpec<'Inputs, 'Output> =
4331 {
4432 Description = " My Command"
4533 Inputs = []
46- GlobalInputs = []
4734 Aliases = []
4835 ExtraInputs = []
4936 Handler = def< unit -> 'Output> // Support unit -> 'Output handler by default
@@ -58,7 +45,6 @@ type BaseCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>() =
5845 {
5946 Description = spec.Description
6047 Inputs = spec.Inputs
61- GlobalInputs = spec.GlobalInputs
6248 Aliases = spec.Aliases
6349 ExtraInputs = spec.ExtraInputs
6450 Handler = handler
@@ -216,14 +202,6 @@ type BaseCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>() =
216202 Help.HelpAction() .Invoke( ctx.ParseResult) |> Task.FromResult
217203 ) spec
218204
219- [<CustomOperation( " addGlobalOption" ) >]
220- member this.AddGlobalOption ( spec : CommandSpec < 'Inputs , 'Output >, globalInput : ActionInput ) =
221- { spec with GlobalInputs = spec.GlobalInputs @ [ globalInput ] }
222-
223- [<CustomOperation( " addGlobalOptions" ) >]
224- member this.AddGlobalOptions ( spec : CommandSpec < 'Inputs , 'Output >, globalInputs : ActionInput seq ) =
225- { spec with GlobalInputs = spec.GlobalInputs @ ( globalInputs |> List.ofSeq) }
226-
227205 [<Obsolete( " 'setCommand' has been deprecated in favor of 'addCommand' or 'addCommands'." ) >]
228206 [<CustomOperation( " setCommand" ) >]
229207 member this.SetCommand ( spec : CommandSpec < 'Inputs , 'Output >, subCommand : System.CommandLine.Command ) =
@@ -239,6 +217,20 @@ type BaseCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>() =
239217 member this.AddCommands ( spec : CommandSpec < 'Inputs , 'Output >, subCommands : System.CommandLine.Command seq ) =
240218 { spec with SubCommands = spec.SubCommands @ ( subCommands |> Seq.toList) }
241219
220+ [<Obsolete( " 'addGlobalInput' has been deprecated in favor of using `addInputs` with 'recursive' options." ) >]
221+ [<CustomOperation( " addGlobalOption" ) >]
222+ member this.AddGlobalOption ( spec : CommandSpec < 'Inputs , 'Output >, globalInput : ActionInput ) =
223+ this.AddInputs( spec, [ globalInput ])
224+
225+ [<Obsolete( " 'addGlobalInputs' has been deprecated in favor of using `addInputs` with 'recursive' options." ) >]
226+ [<CustomOperation( " addGlobalOptions" ) >]
227+ member this.AddGlobalOptions ( spec : CommandSpec < 'Inputs , 'Output >, globalInputs : ActionInput seq ) =
228+ for gi in globalInputs do
229+ match gi.Source with
230+ | ParsedOption o -> o.Recursive <- true
231+ | _ -> () // Ignore non-option inputs
232+ this.AddInputs( spec, globalInputs)
233+
242234 /// Adds an alias to the command.
243235 [<CustomOperation( " addAlias" ) >]
244236 member this.AddAlias ( spec : CommandSpec < 'Inputs , 'Output >, alias : string ) =
@@ -343,7 +335,6 @@ type CommandLineConfigurationBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>()
343335 this.CommandLineConfiguration.RootCommand
344336 |> this.SetGeneralProperties spec
345337 |> this.SetHandlerUnit spec
346- |> addGlobalOptionsToCommand spec.GlobalInputs
347338 |> ignore
348339 this.CommandLineConfiguration
349340
@@ -352,7 +343,6 @@ type CommandLineConfigurationBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>()
352343 this.CommandLineConfiguration.RootCommand
353344 |> this.SetGeneralProperties spec
354345 |> this.SetHandlerInt spec
355- |> addGlobalOptionsToCommand spec.GlobalInputs
356346 |> ignore
357347 this.CommandLineConfiguration
358348
@@ -361,7 +351,6 @@ type CommandLineConfigurationBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>()
361351 this.CommandLineConfiguration.RootCommand
362352 |> this.SetGeneralProperties spec
363353 |> this.SetHandlerTask spec
364- |> addGlobalOptionsToCommand spec.GlobalInputs
365354 |> ignore
366355 this.CommandLineConfiguration
367356
@@ -398,7 +387,6 @@ type RootCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>(args: string ar
398387 this.CommandLineConfiguration.RootCommand
399388 |> this.SetGeneralProperties spec
400389 |> this.SetHandlerUnit spec
401- |> addGlobalOptionsToCommand spec.GlobalInputs
402390
403391 rootCommand.Parse( args, this.CommandLineConfiguration) .Invoke()
404392
@@ -408,7 +396,6 @@ type RootCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>(args: string ar
408396 this.CommandLineConfiguration.RootCommand
409397 |> this.SetGeneralProperties spec
410398 |> this.SetHandlerInt spec
411- |> addGlobalOptionsToCommand spec.GlobalInputs
412399
413400 rootCommand.Parse( args, this.CommandLineConfiguration) .Invoke()
414401
@@ -418,7 +405,6 @@ type RootCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>(args: string ar
418405 this.CommandLineConfiguration.RootCommand
419406 |> this.SetGeneralProperties spec
420407 |> this.SetHandlerTask spec
421- |> addGlobalOptionsToCommand spec.GlobalInputs
422408
423409 rootCommand.Parse( args, this.CommandLineConfiguration) .InvokeAsync()
424410
@@ -428,7 +414,6 @@ type RootCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>(args: string ar
428414 this.CommandLineConfiguration.RootCommand
429415 |> this.SetGeneralProperties spec
430416 |> this.SetHandlerTaskInt spec
431- |> addGlobalOptionsToCommand spec.GlobalInputs
432417
433418 rootCommand.Parse( args, this.CommandLineConfiguration) .InvokeAsync()
434419
@@ -447,21 +432,18 @@ type CommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>(name: string) =
447432 Command( name)
448433 |> this.SetGeneralProperties spec
449434 |> this.SetHandlerUnit spec
450- |> addGlobalOptionsToCommand spec.GlobalInputs
451435
452436 /// Executes a Command with a handler that returns int.
453437 member this.Run ( spec : CommandSpec < 'Inputs , int >) =
454438 Command( name)
455439 |> this.SetGeneralProperties spec
456440 |> this.SetHandlerInt spec
457- |> addGlobalOptionsToCommand spec.GlobalInputs
458441
459442 /// Executes a Command with a handler that returns a Task<unit> or Task<int>.
460443 member this.Run ( spec : CommandSpec < 'Inputs , Task < 'ReturnValue >>) =
461444 Command( name)
462445 |> this.SetGeneralProperties spec
463446 |> this.SetHandlerTask spec
464- |> addGlobalOptionsToCommand spec.GlobalInputs
465447
466448
467449/// Builds a `System.CommandLineConfiguration` that can be passed to the `CommandLineParser.Parse` static method using computation expression syntax.
0 commit comments