Skip to content

Commit

Permalink
Rework type reflection, help and subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
n0s4 committed Aug 10, 2024
1 parent e8e6a53 commit 6835659
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 598 deletions.
2 changes: 0 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ pub fn build(b: *std.Build) void {
const example_option = b.option(
enum {
overview,
subcommands,
trailing,
git,
},
"example",
"Example to run for example step (default = overview).",
Expand Down
94 changes: 0 additions & 94 deletions examples/git.zig

This file was deleted.

28 changes: 27 additions & 1 deletion examples/overview.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn main() !void {
// This can be overridden in the call to `flags.parse`.
const Overview = struct {
// Optional description of the program.
pub const help =
pub const description =
\\This is a dummy command for testing purposes.
\\There are a bunch of options for demonstration purposes.
;
Expand Down Expand Up @@ -68,6 +68,32 @@ const Overview = struct {
second: u32,
// Optional positional arguments must come at the end.
third: ?u8,

pub const descriptions = .{
.first = "The first argument (required)",
.second = "The second argument (required)",
.third = "The third argument (optional)",
};
},

// Subcommands can be defined through the `command` field, which should be a union with struct
// fields which are defined the same way this struct is. Subcommands may be nested.
command: union(enum) {
frobnicate: struct {
pub const descriptions = .{
.level = "Frobnication level",
};

level: u8,
},
defrabulise: struct {
supercharge: bool,
},

pub const descriptions = .{
.frobnicate = "Frobnicate everywhere",
.defrabulise = "Defrabulise everyone",
};
},

// Optional declaration to define shorthands. These can be chained e.g '-fs large'.
Expand Down
79 changes: 0 additions & 79 deletions examples/subcommands.zig

This file was deleted.

Loading

0 comments on commit 6835659

Please sign in to comment.