You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9763f0c
Browse filesBrowse the repository at this point in the historyBrowse files
As an alternative to the `inputs` tuple, the `input { }` computation expression composes any number of inputs into a *single* composite input using applicative `let!`/`and!` bindings. Each value is named at its binding site, and the action receives whatever shape you `return` — typically an anonymous record:
70
+
71
+
```F#
72
+
[<EntryPoint>]
73
+
let main argv =
74
+
rootCommand argv {
75
+
description "Appends words together"
76
+
input {
77
+
let! words = option<string[]> "--word" |> alias "-w" |> desc "A list of words to be appended"
78
+
and! separator = optionMaybe "--separator" |> alias "-s" |> desc "A character that will separate the joined words."
This removes the 8-input tuple limit (bind as many inputs as you like with `and!`) and the need to keep the `inputs` tuple and the `setAction` parameters in positional sync.
89
+
90
+
The composite input is a normal `ActionInput<'T>`, so it is first-class — all of these work:
91
+
92
+
```F#
93
+
// Declared separately and passed to `inputs`:
94
+
let io = input {
95
+
let! words = option<string[]> "--word"
96
+
and! separator = option "--separator" |> def ", "
97
+
return {| Words = words; Separator = separator |}
98
+
}
99
+
100
+
rootCommand argv {
101
+
inputs io
102
+
setAction (fun io -> ...)
103
+
}
104
+
105
+
// Mixed into an `inputs` tuple alongside plain inputs:
106
+
rootCommand argv {
107
+
inputs (io, option<bool> "--verbose")
108
+
setAction (fun (io, verbose) -> ...)
109
+
}
110
+
111
+
// Nested inside another `input { }` — great for sharing common option groups
112
+
// between commands (shared options are registered only once per command):
* Bind all sources in one `let!`/`and!` group. A second sequential `let!` is a compile error (`Bind` is deliberately not defined), because an input cannot depend on another input's parsed value — the full input set must be known before parsing.
132
+
* Declare one `input { }` block per command, before `setAction`.
133
+
*`configureParser` / `configureInvocation` must appear *before* an inline `input { }` block.
134
+
135
+
136
+
66
137
## Input API
67
138
The new `Input` module contains functions for the underlying System.CommandLine `Option` and `Argument` properties.
0 commit comments