Skip to content

Commit 0fe1e13

Browse files
committed
Added hidden to Command and Input.
1 parent d3dbaa3 commit 0fe1e13

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/FSharp.SystemCommandLine/CommandBuilders.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type CommandSpec<'Inputs, 'Output> =
3737
SubCommands: System.CommandLine.Command list
3838
/// Registers extra inputs that can be parsed via the InvocationContext if more than 8 are required.
3939
ExtraInputs: ActionInput list
40+
Hidden: bool
4041
}
4142
static member Default =
4243
{
@@ -47,6 +48,7 @@ type CommandSpec<'Inputs, 'Output> =
4748
ExtraInputs = []
4849
Handler = def<unit -> 'Output> // Support unit -> 'Output handler by default
4950
SubCommands = []
51+
Hidden = false
5052
}
5153

5254
/// Contains shared operations for building a `rootCommand`, `command` or `commandLineConfiguration` CE.
@@ -61,6 +63,7 @@ type BaseCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>() =
6163
ExtraInputs = spec.ExtraInputs
6264
Handler = handler
6365
SubCommands = spec.SubCommands
66+
Hidden = spec.Hidden
6467
}
6568

6669
/// Converts up to 8 handler inputs into a tuple of the specified action input type.
@@ -275,6 +278,7 @@ type BaseCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>() =
275278
)
276279
spec.SubCommands |> List.iter cmd.Add
277280
spec.Aliases |> List.iter cmd.Aliases.Add
281+
cmd.Hidden <- spec.Hidden
278282
cmd
279283

280284
/// Sets a command handler that returns `unit`.
@@ -433,6 +437,11 @@ type RootCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>(args: string ar
433437
type CommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>(name: string) =
434438
inherit BaseCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>()
435439

440+
/// Hides the command from the help output.
441+
[<CustomOperation("hidden")>]
442+
member this.Hidden (spec: CommandSpec<'Inputs, 'Output>) =
443+
{ spec with Hidden = true }
444+
436445
/// Returns a Command with a handler that returns unit.
437446
member this.Run (spec: CommandSpec<'Inputs, unit>) =
438447
Command(name)

src/FSharp.SystemCommandLine/Inputs.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ module Input =
224224
input
225225
|> editOption (fun a -> a.AllowMultipleArgumentsPerToken <- true)
226226

227+
/// Hides an option or argument from the help output.
228+
let hidden (input: ActionInput<'T>) =
229+
input
230+
|> editOption (fun o -> o.Hidden <- true)
231+
|> editArgument (fun a -> a.Hidden <- true)
232+
227233
/// Converts an `Option<'T>` to an `ActionInput<'T>` for usage with the command builders.
228234
let ofOption (o: Option<'T>) =
229235
ActionInput.OfOption<'T> o

0 commit comments

Comments
 (0)