You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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*ascommanderfrom'commander'classCommandextendscommander.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 reasonoption.flags=`${option.flags}, -b`}super.addOption(option)}}constcli=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:
constcli=createCli({router,modify: modifier=>{modifier(router.deeply.nested.fooProcedure,command=>{command.addHelpText(`be careful with this, it's destructive`)})modifier(router.some.other.barProcedure,command=>{constabcOption=command.options.find(o=>o.flags.includes('--abc')abcOption?.hideHelp()})}})cli.run()
or something like that
devil's advocate to myself, here's how you'd do that today:
constcli=createCli({router})constprogram=cli.buildProgram()asimport('commander').CommandconstfindSubcommand=(...path: string[])=>{letcommand=programastypeofprogram|undefinedfor(constpofpath)command=command?.commands.find(c=>c.name===p)if(!command)thrownewError(`command at path ${path.join('.')} not found`)returncommand}findSubcommand('deeply','nested','foo-procedure').addHelpText(`be careful with this, it's destructive`)findSubcommand('some','other','bar-procedure').options.find(o=>o.flags.includes('--abc')?.hideHelp()cli.run({},program)
which is really not so bad, not all that much more verbose and more obvious what it's doing. but not type safe
Activity
mmkal commentedon Jun 11, 2025
Another possible API:
or something like that
devil's advocate to myself, here's how you'd do that today:
which is really not so bad, not all that much more verbose and more obvious what it's doing. but not type safe