mmkal / trpc-cli

Turn a tRPC router into a type-safe, fully-functional, documented CLI
Other
77 stars 2 forks source link

Feature request: repl mode #12

Open kran6a opened 3 months ago

kran6a commented 3 months ago

Add the option to make the CLI app enter a repl loop when executed without arguments (ie: ./cli.ts). In repl mode you get autocompletion (via the readline autocompletion interface) when typying commands and their arguments.

mmkal commented 3 months ago

I like this idea. Would need to think through when to enter repl mode:

  1. when no command is passed?
  2. what about when there's a default command?
  3. when an invalid command is passed?
  4. when a command is passed but it's missing required flags?
  5. when invalid flags are passed?

My instinct is yes to 1 and no to all the others, but 4 might be useful too.

Did you have something in mind, how you would want to configure this as a developer, and how you'd want end users to be able to use it?

kran6a commented 3 months ago

I would trigger repl mode in two scenarios:

  1. When it is configured in the .run method
    
    import {trpcCli} from 'trpc-cli'

const cli = trpcCli({router: yourRouter})

cli.run({ repl: true //type boolean | string (argument required to trigger the repl mode, bonus points if it is type-checked so that it cannot collide with a router method) })


2. When no command is passed, there is no default command configured and `cli.run()` was NOT called with repl: false (so that you can opt-out of repl in case you are using a cli tool as part of a bash script where entering repl mode would be undesirable).