Skip to content

low-level configurability #103

@mmkal

Description

@mmkal

at this point there are a fair few decisions that trpc-cli makes for you when deciding how to create options, negations etc.

it'd be overkill to provide explicit levers to pull to change all of that, but maybe the commander module could be injectable so that people can just do their own little hacks like

import * as commander from 'commander'

class Command extends commander.Command {
  addOption(option: Option) {
    if (this.name() === 'say-hello' && option.name() === 'foo') {
      option.description(`${option.description()} - btw this has very verbose output so mebe use jq or whatever`)
    }
    if (this.name() === 'say-goodbye' && option.name() === 'bar') {
      // router comes from another module we can't add `.meta` to for some reason
      option.flags = `${option.flags}, -b`
    }
    super.addOption(option)
  }
}

const cli = createCli({
  router: myRouter,
  commander: {....commander, Command}
})
cli.run()

This is theoretically possible now via buildProgram() but it's (even more) inconvenient.

Or opt-out of the booleans-get-negated-automatically functionality of #102:

import * as commander from 'commander'

class Command extends commander.Command {
  addOption(option: Option) {
    if (option.flags.includes('--no-') return
    super.addOption(option)
  }
}

const cli = createCli({
  router: myRouter,
  commander: {....commander, Command}
})
cli.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions