cmd-ts
cmd-ts copied to clipboard
Add a `conditional` combinator
Needs design though. I thought about something like
conditional({ long: string, short?: string }, ArgParser<T>) // ArgParser<T | undefined>
So you can describe something like
command({
// ...,
args: {
// ...,
deploy: conditional(
{
long: 'deploy'
},
object({
tag: ... // can be required if `--deploy` was provided!
})),
},
// then it'll be more declarative
handler({ deploy }) {
if (deploy) {
deploy.tag // 😁
}
}
}