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
Copy file name to clipboardExpand all lines: README.md
+49Lines changed: 49 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -338,6 +338,55 @@ let main argv =
338
338
}
339
339
```
340
340
341
+
## Customizing the Default Pipeline
342
+
343
+
System.CommandLine has a `CommandLineBuilder` that allows the user to customize various behaviors.
344
+
345
+
FSharp.SystemCommandLine is configured to use the built-in defaults (via `CommandLineBuilder().UseDefaults()`), but you can easily override them via the `usePipeline` custom operation which gives you access to the `CommandLineBuilder`.
346
+
347
+
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`:
348
+
349
+
```F#
350
+
module TokenReplacerExample
351
+
352
+
open FSharp.SystemCommandLine
353
+
open System.CommandLine.Builder // Necessary when overriding the builder via usePipeline
354
+
355
+
let app (package: string) =
356
+
if package.StartsWith("@") then
357
+
printfn $"{package}"
358
+
0
359
+
else
360
+
eprintfn "The package name does not start with a leading @"
361
+
1
362
+
363
+
[<EntryPoint>]
364
+
let main argv =
365
+
366
+
// The package option needs to accept strings that start with "@" symbol.
367
+
// For example, "--package @shoelace-style/shoelace".
368
+
// To accomplish this, we will need to modify the default pipeline settings below.
369
+
let package = Input.Option([ "--package"; "-p" ], "A package name that may have a leading '@' character.")
370
+
371
+
rootCommand argv {
372
+
description "Can be called with a leading '@' package"
373
+
374
+
usePipeline (fun builder ->
375
+
// Override default token replacer to ignore `@` processing
376
+
builder.UseTokenReplacer(fun _ _ _ -> false)
377
+
)
378
+
379
+
inputs package
380
+
setHandler app
381
+
}
382
+
383
+
```
384
+
385
+
As you can see, there are a lot of options that can be configured here (note that you need to `open System.CommandLine.Builder`):
While the `Input.Argument` and `Input.Option` helper methods are useful for most common scenarios, sometimes it may be necessary to manually define inputs using the underlying `System.CommandLine` base library. This will make it easier to investigate the various overloads and take advantage of other features like custom validation.
0 commit comments