Skip to content

Commit 5050816

Browse files
authored
Update README.md for beta7 changes.
1 parent 6f3211a commit 5050816

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

README.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,13 @@ let main argv =
591591
592592
```
593593

594-
### Creating a Root Command Parser
594+
### Manually Invoking a Root Command
595595

596-
If you want to manually invoke your root command, use the `rootCommandParser` CE (because the `rootCommand` CE is auto-executing).
596+
If you want to manually invoke your root command, use the `ManualInvocation.rootCommand` computation expression.
597+
598+
NOTES:
599+
* `ManualInvocation.rootCommand` does not take the CLI args as an input.
600+
* `ManualInvocation.rootCommand` does not auto-execute.
597601

598602
```F#
599603
open FSharp.SystemCommandLine
@@ -610,17 +614,24 @@ let main argv =
610614
let words = option "--word" |> alias -w" |> desc "A list of words to be appended"
611615
let separator = optionMaybe "--separator" |> alias "-s" |> desc "A character that will separate the joined words."
612616
613-
let cfg =
614-
commandLineConfiguration {
617+
let cmd =
618+
ManualInvocation.rootCommand {
615619
description "Appends words together"
616620
inputs (words, separator)
617621
setAction app
618622
}
619623
620-
let parseResult = cfg.Parse(argv)
621-
parseResult.Invoke()
624+
let parseResult = cmd.Parse(argv)
625+
626+
// parseResult.InvokeAsync()
627+
parseResult.Invoke()
622628
```
623629

630+
Notes about invocation:
631+
* At this point, you can call `parseResult.Invoke()` or `parseResult.InvokeAsync()`
632+
* You can optionally pass in an `InvocationConfiguration`:
633+
* `parseResult.Invoke(InvocationConfiguration(EnableDefaultExceptionHandler = false))`
634+
624635
### Showing Help as the Default
625636
A common design is to show help information if no commands have been passed:
626637

@@ -649,11 +660,12 @@ let main argv =
649660
}
650661
```
651662

652-
## Command Line Configuration
663+
## Configuration
653664

654-
System.CommandLine has a `CommandLineConfiguration` that allows the user to customize various behaviors.
665+
System.CommandLine (>= v2 beta7) has `ParserConfiguration` and `InvocationConfiguration` to allow the user to customize various behaviors.
655666

656-
FSharp.SystemCommandLine uses the defaults from `CommandLineConfiguration`, but you can override them via the `configure` custom operation which gives you access to the `CommandLineConfiguration`.
667+
* FSharp.SystemCommandLine `configureParser` gives you access to the underlying `ParserConfiguration`.
668+
* FSharp.SystemCommandLine `configureInvocation` gives you access to the underlying `InvocationConfiguration`. NOTE: This operation is not available on the `ManualInvocation.rootCommand`..
657669

658670
For example, the default behavior intercepts input strings that start with a "@" character via the "TryReplaceToken" feature. This will cause an issue if you need to accept input that starts with "@". Fortunately, you can disable this via `usePipeline`:
659671

@@ -681,10 +693,13 @@ let main argv =
681693
682694
rootCommand argv {
683695
description "Can be called with a leading '@' package"
684-
configure (fun cfg ->
696+
configureParser (fun cfg ->
685697
// Override default token replacer to ignore `@` processing
686698
cfg.ResponseFileTokenReplacer <- null
687699
)
700+
configureInvocation (fun cfg ->
701+
cfg.EnableDefaultExceptionHandler <- false
702+
)
688703
inputs package
689704
setAction app
690705
}

0 commit comments

Comments
 (0)