Closed FObersteiner closed 3 months ago
This could be addressed by a general purpose "description" declaration, through which you could describe the arguments free-form (as well as other details about the command).
I like the simplicity of that solution but if you want something more structured maybe something like this...?
const MyCommand = struct {
pub const args_usage = .{
.{ "file", "file to use" },
.{ "arg2", "description" },
// ...
}
}
I like the simplicity of that solution
That's what I had in mind. As I briefly mentioned, in the case of arguments being commands that in turn take arguments, a more structured approach might be more appropriate. But that might be added later, no?
Adding a general purpose description to any command is now supported:
// examples/overview.zig
pub const help =
\\This is a dummy command for testing purposes.
\\There are a bunch of options for demonstration purposes.
;
$ zig build run-example -- -h
Usage: example [options]
This is a dummy command for testing purposes.
There are a bunch of options for demonstration purposes.
Options:
-f, --force Use the force
--optional You don't need this one
--override You can change this if you want
--required You have to set this!
-a, --age How old?
-p, --power How strong?
-s, --size How big?
small The least big
medium Not quite small, not quite big
large The biggest
-h, --help Show this help and exit
I think we agree that this adequately covers your request, so I'll close this for now.
PS: If you want to import from the main branch since I've not made a whole release for this, update your dependency URL like so:
$ zig fetch --save https://github.com/n0s4/flags/archive/refs/heads/main.tar.gz
That'll get me started, thanks a lot for the quick update!
...just for the help message. So that a user knows upfront that they need to provide n arguments which mean x, y, z etc. So this could basically be just another text (
[]const u8
) field with a specific name I guess.Here's a crude example, so you get the idea:
The positional arguments could also be commands, so this might require some more thought.