Skip to content

Commit 6eeca94

Browse files
committed
DeprecatedsetCommand in favor of addCommand/addCommands
1 parent 00556fe commit 6eeca94

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/FSharp.SystemCommandLine/CommandBuilders.fs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,19 @@ type BaseCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'I, 'J, 'K, 'L, 'M, 'N,
118118
member this.SetHandler (spec: CommandSpec<'Inputs, 'Output>, handler: 'Inputs -> 'Output) =
119119
newHandler handler spec
120120

121-
[<CustomOperation("setCommand")>]
122-
member this.SetHandler (spec: CommandSpec<'Inputs, 'Output>, subCommand: System.CommandLine.Command) =
121+
[<Obsolete("'setCommand' has been deprecated in favor of 'addCommand' or 'addCommands`.")>]
122+
[<CustomOperation("setCommand")>]
123+
member this.SetCommand (spec: CommandSpec<'Inputs, 'Output>, subCommand: System.CommandLine.Command) =
123124
{ spec with SubCommands = spec.SubCommands @ [ subCommand ] }
124125

126+
[<CustomOperation("addCommand")>]
127+
member this.AddCommand (spec: CommandSpec<'Inputs, 'Output>, subCommands: System.CommandLine.Command) =
128+
{ spec with SubCommands = spec.SubCommands @ [ subCommands ] }
129+
130+
[<CustomOperation("addCommands")>]
131+
member this.AddCommands (spec: CommandSpec<'Inputs, 'Output>, subCommands: System.CommandLine.Command seq) =
132+
{ spec with SubCommands = spec.SubCommands @ (subCommands |> Seq.toList) }
133+
125134
/// Sets general properties on the command.
126135
member this.SetGeneralProperties (spec: CommandSpec<'T, 'U>) (cmd: Command) =
127136
cmd.Description <- spec.Description

src/TestConsole/ProgramSubCommand.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ let main argv =
4141
rootCommand argv {
4242
description "File System Manager"
4343
setHandler id
44-
setCommand listCmd
45-
setCommand deleteCmd
44+
addCommands [ listCmd; deleteCmd ]
4645
}
4746

4847

src/Tests/SubCommandAppTest.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ let rootCmd argstr listCmdHandler deleteCmdHandler =
2929
testRootCommand argstr {
3030
description "File System Manager"
3131
setHandler id
32-
setCommand (listCmd listCmdHandler)
33-
setCommand (deleteCmd deleteCmdHandler)
32+
addCommand (listCmd listCmdHandler)
33+
addCommand (deleteCmd deleteCmdHandler)
3434
}
3535
|> ignore
3636

0 commit comments

Comments
 (0)