cmd-ts icon indicating copy to clipboard operation
cmd-ts copied to clipboard

Add a `conditional` combinator

Open Schniz opened this issue 4 years ago • 0 comments

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 // 😁
    }
  }
}

Schniz avatar May 10 '20 08:05 Schniz