Skip to content

Commit fc34f3f

Browse files
committed
Added defaultValueMaybe
1 parent 93af289 commit fc34f3f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/FSharp.SystemCommandLine/Inputs.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ module Input =
9494
/// An alias for `defaultValue` to set the default value of an option or argument.
9595
let def = defaultValue
9696

97+
/// Sets the default value of an option or argument.
98+
let defaultValueMaybe (defaultValue: 'T option) (input: ActionInput<'T>) =
99+
match defaultValue with
100+
| Some defaultValue' ->
101+
input
102+
|> editOption (fun o -> o.DefaultValueFactory <- (fun _ -> defaultValue'))
103+
|> editArgument (fun a -> a.DefaultValueFactory <- (fun _ -> defaultValue'))
104+
| None ->
105+
input
106+
97107
/// Sets the default value factory of an option or argument.
98108
let defaultValueFactory (defaultValueFactory: Parsing.ArgumentResult -> 'T) (input: ActionInput<'T>) =
99109
input

0 commit comments

Comments
 (0)