Skip to content

Commit 4937465

Browse files
authored
Added example with > 8 inputs
1 parent 2a062ff commit 4937465

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,40 @@ let main argv =
198198
|> Async.RunSynchronously
199199
```
200200

201+
### Example with more than 8 inputs
202+
Currently, a command handler function is limited to accept a tuple with no more than eight inputs.
203+
If you need more, you can pass in the InvocationContext to your handler and manually get as many input values as you like (assuming they have been registered via the rootCommand or command builder's `add` operation:
204+
205+
```F#
206+
module Program
207+
208+
open FSharp.SystemCommandLine
209+
210+
module Parameters =
211+
let words = Input.Option<string[]>(["--word"; "-w"], Array.empty, "A list of words to be appended")
212+
let separator = Input.OptionMaybe<string>(["--separator"; "-s"], "A character that will separate the joined words.")
213+
214+
let app (ctx: System.CommandLine.Invocation.InvocationContext) =
215+
// Manually parse as many parameters as you need
216+
let words = Parameters.words.GetValue ctx
217+
let separator = Parameters.separator.GetValue ctx
218+
219+
// Do work
220+
let separator = separator |> Option.defaultValue ", "
221+
System.String.Join(separator, words) |> printfn "Result: %s"
222+
0
223+
224+
[<EntryPoint>]
225+
let main argv =
226+
rootCommand argv {
227+
description "Appends words together"
228+
inputs (Input.Context())
229+
setHandler app
230+
add Parameters.words
231+
add Parameters.separator
232+
}
233+
```
234+
201235
### Example using Microsoft.Extensions.Hosting
202236

203237
This example requires the following nuget packages:

0 commit comments

Comments
 (0)