I'm writing a CLI using Heroku's CLI framework oclif. It works great, but I would like to have Git-like subcommands, something like that:
$ mycli mycommand subcommand
$ mycli mycommand subcommand --flags="are awesome"
$ mycli mycommand another-subcommand --name="John Doe"
I've gone through the docs but I couldn't find any information related to command structure, layout, hierarchy, etc. I could write mycommand
as a normal command and have a switch on argv's first argument, but my subcommands accept different flags, so I lose oclif's ability to report some help when someone runs mycli help mycommand
.
So, my question is: what is the best way to create subcommands using oclif?
You can create the following structure:
This would produce commands like:
One thing that I've noticed is that if you want to share some flags or arguments with other commands you either will have to use a base class for that or declare the flags/switches/arguments on another file and import them on the desired command