rewrite generate_help for personal style

- Output to stdin instead of a file
- Less nesting
- Utilize ranged for loops instead of while loops
- Eliminate unnecessary state tracking
- Put help in a struct
This commit is contained in:
Mitchell Hashimoto
2024-01-19 22:22:29 -08:00
parent f9ac37cdf7
commit 203b38fdac
3 changed files with 55 additions and 193 deletions

View File

@@ -69,6 +69,21 @@ pub const Action = enum {
.@"list-colors" => try list_colors.run(alloc),
};
}
/// Returns the filename associated with an action. This is a relative
/// path from the root src/ directory.
pub fn file(comptime self: Action) []const u8 {
comptime {
const filename = filename: {
const tag = @tagName(self);
var filename: [tag.len]u8 = undefined;
_ = std.mem.replace(u8, tag, "-", "_", &filename);
break :filename &filename;
};
return "cli/" ++ filename ++ ".zig";
}
}
};
test "parse action none" {