Skip to content

Commit

Permalink
Added OptionRequired overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMarr committed Apr 17, 2022
1 parent 9a25d9f commit a397ae4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
25 changes: 22 additions & 3 deletions src/FSharp.SystemCommandLine/Inputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type HandlerInput<'T>(inputType: HandlerInputSource) =
static member OfOption<'T>(o: Option<'T>) = o :> Option |> ParsedOption |> HandlerInput<'T>
static member OfArgument<'T>(a: Argument<'T>) = a :> Argument |> ParsedArgument |> HandlerInput<'T>


/// Creates CLI options and arguments to be passed as command `inputs`.
type Input =

Expand All @@ -44,7 +45,7 @@ type Input =
description = (description |> Option.defaultValue null)
)
|> HandlerInput.OfOption

/// Creates a CLI option of type 'T with a default value.
static member Option<'T>(name: string, defaultValue: 'T, ?description: string) =
Option<'T>(
Expand All @@ -63,6 +64,24 @@ type Input =
)
|> HandlerInput.OfOption

/// Creates a CLI option of type 'T that is required.
static member OptionRequired<'T>(name: string, ?description: string) =
Option<'T>(
name,
description = (description |> Option.defaultValue null),
IsRequired = true
)
|> HandlerInput.OfOption

/// Creates a CLI option of type 'T that is required.
static member OptionRequired<'T>(aliases: string seq, ?description: string) =
Option<'T>(
aliases |> Seq.toArray,
description = (description |> Option.defaultValue null),
IsRequired = true
)
|> HandlerInput.OfOption

/// Creates a CLI option of type 'T option.
static member OptionMaybe<'T>(name: string, ?description: string) =
Option<'T option>(
Expand All @@ -86,7 +105,7 @@ type Input =
| None -> failwith "F# Option can only be used with a single argument."
),
description = (description |> Option.defaultValue null)
)
)
|> HandlerInput.OfOption

/// Creates a CLI argument of type 'T.
Expand All @@ -103,7 +122,7 @@ type Input =
name,
getDefaultValue = (fun () -> defaultValue),
description = (description |> Option.defaultValue null)
)
)
|> HandlerInput.OfArgument

/// Creates a CLI argument of type 'T option.
Expand Down
7 changes: 3 additions & 4 deletions src/TestConsole/TestConsole.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
</PropertyGroup>

<ItemGroup>
<Content Include="Properties\launchSettings.json" />
<Compile Include="ProgramAlt1.fs" />
<Compile Include="ProgramNoArgs.fs" />
<Compile Include="ProgramSubCommand.fs" />
<Compile Include="ProgramTask.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FSharp.SystemCommandLine\FSharp.SystemCommandLine.fsproj" />
</ItemGroup>
<ItemGroup />

<ItemGroup>
<Folder Include="Properties\" />
<ProjectReference Include="..\FSharp.SystemCommandLine\FSharp.SystemCommandLine.fsproj" />
</ItemGroup>

</Project>

0 comments on commit a397ae4

Please sign in to comment.