Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ The new `Input` module contains functions for the underlying System.CommandLine
* `optionMaybe` creates a named `Option<'T option>` that defaults to `None`.

### Input Properties
* `acceptLegalFilePathsOnly` sets the option or argument to accept only values representing legal file paths.
* `alias` adds an `Alias` to an `Option`
* `aliases` adds one or more aliases to an `Option`
* `desc` adds a description to an `Option` or `Argument`
* `defaultValue` or `def` provides a default value to an `Option` or `Argument`
* `defFactory` assigns a default value factor to an `Option` or `Argument`
* `helpName` adds the name used in help output to describe the option or argument.
* `required` marks an `Option` as required
* `validate` allows you to return a `Result<unit, string>` for the parsed value
* `validateFileExists` ensures that the `FileInfo` exists
Expand Down
12 changes: 12 additions & 0 deletions src/FSharp.SystemCommandLine/Inputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ module Input =
| _ -> ()
input

/// Configures the option or argument to accept only values representing legal file paths.
let acceptLegalFilePathsOnly (input: ActionInput<'T>) =
input
|> editOption (fun o -> o.AcceptLegalFilePathsOnly() |> ignore)
|> editArgument (fun a -> a.AcceptLegalFilePathsOnly() |> ignore)

/// Adds one or more aliases to an option.
let aliases (aliases: string seq) (input: ActionInput<'T>) =
input |> editOption (fun o -> aliases |> Seq.iter o.Aliases.Add)
Expand Down Expand Up @@ -100,6 +106,12 @@ module Input =
|> editOption (fun o -> o.DefaultValueFactory <- defaultValueFactory)
|> editArgument (fun a -> a.DefaultValueFactory <- defaultValueFactory)

/// The name used in help output to describe the option or argument.
let helpName (helpName: string) (input: ActionInput<'T>) =
input
|> editOption (fun o -> o.HelpName <- helpName)
|> editArgument (fun a -> a.HelpName <- helpName)

/// Marks an option as required.
let required (input: ActionInput<'T>) =
input |> editOption (fun o -> o.Required <- true)
Expand Down