Skip to content

Commit 8f6f68b

Browse files
committed
Updated ProgramTokenReplacer.fs to use usePipline.
1 parent d02ede2 commit 8f6f68b

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

src/FSharp.SystemCommandLine/CommandBuilders.fs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,6 @@ type RootCommandParserBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>() =
334334
this.CommandLineBuilder <- subCommand this.CommandLineBuilder
335335
spec
336336

337-
[<CustomOperation("useTokenReplacer")>]
338-
member this.UseTokenReplacer(spec: CommandSpec<'Inputs, 'Output>, replacer: TryReplaceToken) =
339-
this.CommandLineBuilder.UseTokenReplacer(replacer) |> ignore
340-
spec
341-
342337
/// Executes a Command with a handler that returns unit.
343338
member this.Run (spec: CommandSpec<'Inputs, unit>) =
344339
this.CommandLineBuilder.Command
@@ -378,11 +373,6 @@ type RootCommandBuilder<'A, 'B, 'C, 'D, 'E, 'F, 'G, 'H, 'Output>(args: string ar
378373
this.CommandLineBuilder <- subCommand this.CommandLineBuilder
379374
spec
380375

381-
[<CustomOperation("useTokenReplacer")>]
382-
member this.UseTokenReplacer(spec: CommandSpec<'Inputs, 'Output>, replacer: TryReplaceToken) =
383-
this.CommandLineBuilder.UseTokenReplacer(replacer) |> ignore
384-
spec
385-
386376
/// Executes a Command with a handler that returns unit.
387377
member this.Run (spec: CommandSpec<'Inputs, unit>) =
388378
this.CommandLineBuilder.Command

src/TestConsole/Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let app (words: string array, separator: string option) =
77
System.String.Join(separator, words) |> printfn "Result: %s"
88
0
99

10-
[<EntryPoint>]
10+
//[<EntryPoint>]
1111
let main argv =
1212
let words = Input.Option(["--word"; "-w"], Array.empty, "A list of words to be appended")
1313
let separator = Input.OptionMaybe(["--separator"; "-s"], "A character that will separate the joined words.")
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ProgramTokenReplacer
22

33
open FSharp.SystemCommandLine
4-
open System.CommandLine.Parsing
4+
open System.CommandLine.Builder
55

66
let app (package: string) =
77
if package.StartsWith("@") then
@@ -13,17 +13,20 @@ let app (package: string) =
1313

1414
//[<EntryPoint>]
1515
let main argv =
16-
let package =
17-
Input.Option([ "--package"; "-p" ], "A package with a leading @ name")
16+
17+
// The package option needs to accept strings that start with "@" symbol.
18+
// For example, "--package @shoelace-style/shoelace".
19+
// To accomplish this, we will need to modify the default pipeline settings below.
20+
let package = Input.Option([ "--package"; "-p" ], "A package with a leading @ name")
1821

1922
rootCommand argv {
2023
description "Can be called with a leading @ package"
2124

22-
useTokenReplacer (
23-
// in this case we want to skip @ processing
24-
TryReplaceToken (fun _ _ _ -> false)
25+
usePipeline (fun builder ->
26+
// Skip @ processing
27+
builder.UseTokenReplacer(fun _ _ _ -> false)
2528
)
26-
29+
2730
inputs package
2831
setHandler app
2932
}

0 commit comments

Comments
 (0)