Schniz / cmd-ts

💻 A type-driven command line argument parser
https://cmd-ts.now.sh
MIT License
232 stars 24 forks source link

Adding ability to accept unknown arguments #132

Open DanielKag opened 2 years ago

DanielKag commented 2 years ago

Usecase: Say I'm using cmd-ts to wrap another CLI call. And I don't want to map each of the 2nd CLI's arguments, but just forward them from the original call.

something like:

cmdTs.command({
    name: 'runner',
    acceptUnknownArguments: true,
    args: {
        myArg: flag({
            type: boolean,
            long: 'my-arg',
        }),
        handler: ({ myArg, unknownArgs }) => {
            if (myArg) {
                execa(`node ./otherCli ${unknownArgs.join(' ')}`)
            }
        },
    },
})
Toilal commented 2 years ago

I'm stuck with this exact use case. Would you consider a pull request with the feature ?

Schniz commented 2 years ago

The rest parser (which I need to document) should make this possible. However, there’s a design issue in cmd-ts that I need to really think on how to fix for this to work correctly: help and version flags are circuit breakers and are parsed before the user config. Need to think about how to fix it to allow passing them as free arguments