Replies: 2 comments
-
Hi @vectronic, cliffy supports nested sub-commands. You can implement your example like this: const networkCommand = new Command()
.description("Network wub-command.")
.command("start <network-interface>", "Start a network interface.")
.action(() => console.log("start network..."))
.command("disable", "Disable networking.")
.action(() => console.log("disable network..."));
const storageCommand = new Command()
.description("Device sub-command.")
.command("defrag <drive>", "Defrag a drive.")
.action(() => console.log("defrag device..."))
.command("format <device>", "Format a device.")
.action(() => console.log("format device..."));
await new Command()
.name("my_cli")
.description("My cli.")
.command("network", networkCommand)
.command("storage", storageCommand)
.parse(Deno.args); And the help output of the different commands will look like this: $ my_cli -h
Usage: my_cli
Description:
My cli.
Options:
-h, --help - Show this help.
Commands:
network - Network wub-command.
storage - Device sub-command.
$ my_cli network -h
Usage: my_cli network
Description:
Network wub-command.
Options:
-h, --help - Show this help.
Commands:
start <network-interface> - Start a network interface.
disable - Disable networking.
$ my_cli network start -h
Usage: my_cli network start <network-interface>
Description:
Start a network interface.
Options:
-h, --help - Show this help. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Awesome - thank you very much. I think I was missing the bit about invoking help on the sub-commands. I will try it out! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I wanted to implement 'grouped' sub-commands such as this:
I guess in a way they would be sub-sub-commands scoped to a 'parent' group sub-command...? Let me call them "member sub-commands" for now...
Ideally the "member sub-commands" should be grouped in the help output as well:
Note that I wanted some way for a "member sub-command" to declare it's parent group, so that multiple individual "member sub-command" implementations could be grouped together e.g. If I wanted to add a new "member sub-command" such as
ping
to the example above I would implement a new command and declare it belonged to thenetwork
group.In other words I do not want to/cannot implement the above example like this:
I have read in the manual about "grouped options", but I don't think this would help at all.
Do you think this is possible with cliffy command? Or should I be looking to write something different using cliffy parse?
Beta Was this translation helpful? Give feedback.
All reactions