DEV Community

Discussion on: Build an Interactive CLI Using TypeScript

_christiandimas profile image
Christian Dimas Author

Got it, thanks for the clear explanation!
That's an interesting idea you got.

I'm not quite sure how to build something REPL like (I'll look around for sure!).
But for your use case, I do have an alternative in mind

Because you planned to give your CLI to inexperienced users, what if instead of allowing them to type in the command, you give them a multiple-step prompt just like what I write above with a slightly different approach

Create the CLI as a single type. So it will not have subcommand, simply git (I'll be using git as an example for this)

So when they type:
$ > git

Then they will be presented with the subcommand available (commit, push, etc). Let's say the user chooses commit then the next step you can ask the user to add the message

If they choose push then you can just run the selected action, and not show any next step

Will this be enough for your use case?

I can write a follow-up to this article about the "stateful" CLI, and also publishing the CLI (currently the user needs to have NodeJS installed to get it installed). If you're interested! :)

Cheers,

Chris