zigcli
zigcli copied to clipboard
Simargs support subcommands
For now, simargs doesn't sub commands, add subcommands support will make it much more powerful.
The syntax I could think of is like this:
const App = struct {
help: bool = false,
output: []const u8,
sub_command1: ?struct {
flags1: int,
},
sub_command2: ?struct {
flags1: int,
},
};
Since there are more than one subcommand, we use optional to annotate them.
Or we can represent subcommand with union(enum)
const App = struct {
help: bool = false,
output: []const u8,
sub_command: union(enum) {
sub_cmd1: struct {
flag1: i8,
},
sub_cmd2: struct {
flag1: i8,
},
},
};
Here both method use nested struct to represent subcommands, and it can be nested at any-level!
The help message would look like this:
Usage: mycli [Global-Options] [COMMAND] [Options]
Commands:
sub_command1 xxx
sub_command2 yyy
Options:
-o, --output <file> Output file
-h, --help Print help