Open jiacai2050 opened 3 months ago
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)
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
I prefer the union enum approach.
Thanks, I also like the union style. I will implement this feature in next few weeks.
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:
Since there are more than one subcommand, we use optional to annotate them.
Or we can represent subcommand with
union(enum)
Here both method use nested struct to represent subcommands, and it can be nested at any-level!
The help message would look like this: