Skip to content

Commit a397ae4

Browse files
committed
Added OptionRequired overloads
1 parent 9a25d9f commit a397ae4

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/FSharp.SystemCommandLine/Inputs.fs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type HandlerInput<'T>(inputType: HandlerInputSource) =
2626
static member OfOption<'T>(o: Option<'T>) = o :> Option |> ParsedOption |> HandlerInput<'T>
2727
static member OfArgument<'T>(a: Argument<'T>) = a :> Argument |> ParsedArgument |> HandlerInput<'T>
2828

29+
2930
/// Creates CLI options and arguments to be passed as command `inputs`.
3031
type Input =
3132

@@ -44,7 +45,7 @@ type Input =
4445
description = (description |> Option.defaultValue null)
4546
)
4647
|> HandlerInput.OfOption
47-
48+
4849
/// Creates a CLI option of type 'T with a default value.
4950
static member Option<'T>(name: string, defaultValue: 'T, ?description: string) =
5051
Option<'T>(
@@ -63,6 +64,24 @@ type Input =
6364
)
6465
|> HandlerInput.OfOption
6566

67+
/// Creates a CLI option of type 'T that is required.
68+
static member OptionRequired<'T>(name: string, ?description: string) =
69+
Option<'T>(
70+
name,
71+
description = (description |> Option.defaultValue null),
72+
IsRequired = true
73+
)
74+
|> HandlerInput.OfOption
75+
76+
/// Creates a CLI option of type 'T that is required.
77+
static member OptionRequired<'T>(aliases: string seq, ?description: string) =
78+
Option<'T>(
79+
aliases |> Seq.toArray,
80+
description = (description |> Option.defaultValue null),
81+
IsRequired = true
82+
)
83+
|> HandlerInput.OfOption
84+
6685
/// Creates a CLI option of type 'T option.
6786
static member OptionMaybe<'T>(name: string, ?description: string) =
6887
Option<'T option>(
@@ -86,7 +105,7 @@ type Input =
86105
| None -> failwith "F# Option can only be used with a single argument."
87106
),
88107
description = (description |> Option.defaultValue null)
89-
)
108+
)
90109
|> HandlerInput.OfOption
91110

92111
/// Creates a CLI argument of type 'T.
@@ -103,7 +122,7 @@ type Input =
103122
name,
104123
getDefaultValue = (fun () -> defaultValue),
105124
description = (description |> Option.defaultValue null)
106-
)
125+
)
107126
|> HandlerInput.OfArgument
108127

109128
/// Creates a CLI argument of type 'T option.

src/TestConsole/TestConsole.fsproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<Content Include="Properties\launchSettings.json" />
910
<Compile Include="ProgramAlt1.fs" />
1011
<Compile Include="ProgramNoArgs.fs" />
1112
<Compile Include="ProgramSubCommand.fs" />
1213
<Compile Include="ProgramTask.fs" />
1314
<Compile Include="Program.fs" />
1415
</ItemGroup>
1516

16-
<ItemGroup>
17-
<ProjectReference Include="..\FSharp.SystemCommandLine\FSharp.SystemCommandLine.fsproj" />
18-
</ItemGroup>
17+
<ItemGroup />
1918

2019
<ItemGroup>
21-
<Folder Include="Properties\" />
20+
<ProjectReference Include="..\FSharp.SystemCommandLine\FSharp.SystemCommandLine.fsproj" />
2221
</ItemGroup>
2322

2423
</Project>

0 commit comments

Comments
 (0)