Skip to content

Add custom operation useTokenReplacer #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 1, 2022
Merged

Add custom operation useTokenReplacer #10

merged 3 commits into from
Nov 1, 2022

Conversation

AngelMunoz
Copy link
Contributor

This adds a custom operation to allow us to by-pass a new SCL feature that takes any prefixed @ strings with certain configuration files more info here

I got some pointers from Chet to add a TryReplaceToken delegate so skip this token processing

I wasn't sure how to add a rootCommandTest for this change because it initializes a parser in the helper itself and the parser has to also have a TryReplaceToken delegate for it to work properly, so I added a manual test in the TestConsole project

@JordanMarr
Copy link
Owner

I wasn't aware of this feature, but I can see how this came up as an issue for Pearla.
Thanks for the PR.

@JordanMarr JordanMarr merged commit d02ede2 into JordanMarr:main Nov 1, 2022
@AngelMunoz AngelMunoz deleted the use-token-replacer branch November 1, 2022 15:02
@JordanMarr
Copy link
Owner

JordanMarr commented Nov 1, 2022

Haven't had my morning coffee yet, but after playing with your changes I just remembered that there is a usePipeline custom operation (suggested by Chet) that allows you to customize the builder/pipeline:

module ProgramTokenReplacer

open FSharp.SystemCommandLine
open System.CommandLine.Builder

let app (package: string) =
    if package.StartsWith("@") then
        printfn $"{package}"
        0
    else
        eprintfn "The package name does not start with a leading @"
        1

[<EntryPoint>]
let main argv =
    let package = Input.Option([ "--package"; "-p" ], "A package with a leading @ name")

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

        usePipeline (fun builder -> 
            // Skip @ processing
            builder.UseTokenReplacer(fun _ _ _ -> false)
        )
        
        inputs package
        setHandler app
    }

But I wonder if it would be worth adding something along the lines of disableTokenReplacer to do the same thing:

module ProgramTokenReplacer

open FSharp.SystemCommandLine

let app (package: string) =
    if package.StartsWith("@") then
        printfn $"{package}"
        0
    else
        eprintfn "The package name does not start with a leading @"
        1

[<EntryPoint>]
let main argv =
    let package = Input.Option([ "--package"; "-p" ], "A package with a leading @ name")

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

        disableTokenReplacer

        inputs package
        setHandler app
    }

@AngelMunoz
Copy link
Contributor Author

Oh my... I didn't realize that was the intended use case for the pipeline my bad 😅! in that case then I don't think disableTokenReplacer is required at all it is a very trivial change to be honest I guess if this kind of issue pops up more often then It could be considered

@JordanMarr
Copy link
Owner

There was really no way for you to know. In fact, as I look at the readme, usePipeline is not even mentioned once. 😆
I think I will keep your ProgramTokenReplacer.fs example and put that in the readme as a use case for usePipeline for other people that have this problem.

@JordanMarr
Copy link
Owner

JordanMarr commented Nov 1, 2022

Added a section on customizing the pipeline with your example (as that may be an issue for someone else in the future):

Customizing the Default Pipeline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants