Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/benchmark/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub const Action = enum {
@"is-symbol",
@"osc-parser",

pub const ParseResult = cli.action.ActionParser(@This());

/// Returns the struct associated with the action. The struct
/// should have a few decls:
///
Expand All @@ -38,15 +40,19 @@ pub const Action = enum {
/// An entrypoint for the benchmark CLI.
pub fn main() !void {
const alloc = std.heap.c_allocator;
const action_ = try cli.action.detectArgs(Action, alloc);
const action = action_ orelse return error.NoAction;
try mainAction(alloc, action, .cli);
// Eventually this will be replaced with the args from the "juicy" main.
var iter = try std.process.argsWithAllocator(alloc);
defer iter.deinit();
const result: Action.ParseResult = try .parse(alloc, &iter);
defer result.deinit(alloc);
const action = result.action orelse return error.NoAction;
try mainAction(alloc, action, .{ .cli = result.args });
}

/// Arguments that can be passed to the benchmark.
pub const Args = union(enum) {
/// The arguments passed to the CLI via argc/argv.
cli,
cli: []const [:0]const u8,

/// Simple string arguments, parsed via std.process.ArgIteratorGeneral.
string: []const u8,
Expand Down Expand Up @@ -75,8 +81,8 @@ fn mainActionImpl(
var opts: Options = .{};
defer if (@hasDecl(Options, "deinit")) opts.deinit();
switch (args) {
.cli => {
var iter = try cli.args.argsIterator(alloc);
.cli => |a| {
var iter = try cli.args.argsIterator(alloc, a);
defer iter.deinit();
try cli.args.parse(Options, alloc, &opts, &iter);
},
Expand Down
Loading
Loading