flags: rewrite to allow [:0]const u8 arguments
This also cleans up the code by using @Type(), eliminating the need for the argFlag() and boolFlag() functions. Allowing [:0]const u8 arguments makes this parser useful for river-control commands as well.
This commit is contained in:
@ -65,18 +65,18 @@ pub fn main() !void {
|
||||
fn _main() !void {
|
||||
// This line is here because of https://github.com/ziglang/zig/issues/7807
|
||||
const argv: [][*:0]const u8 = os.argv;
|
||||
const result = flags.parse(argv[1..], &[_]flags.Flag{
|
||||
const result = flags.parser([*:0]const u8, &.{
|
||||
.{ .name = "-h", .kind = .boolean },
|
||||
.{ .name = "-version", .kind = .boolean },
|
||||
}) catch {
|
||||
}).parse(argv[1..]) catch {
|
||||
try io.getStdErr().writeAll(usage);
|
||||
os.exit(1);
|
||||
};
|
||||
if (result.boolFlag("-h")) {
|
||||
if (result.flags.@"-h") {
|
||||
try io.getStdOut().writeAll(usage);
|
||||
os.exit(0);
|
||||
}
|
||||
if (result.boolFlag("-version")) {
|
||||
if (result.flags.@"-version") {
|
||||
try io.getStdOut().writeAll(@import("build_options").version ++ "\n");
|
||||
os.exit(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user