add 'help' command
This commit is contained in:
parent
32b01976d8
commit
73c5214146
1 changed files with 16 additions and 3 deletions
19
src/main.zig
19
src/main.zig
|
@ -230,6 +230,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn doHelp() void {
|
||||||
|
std.debug.warn("scritcher!\n", .{});
|
||||||
|
std.debug.warn("usage: scritcher [run|help|repl]\n", .{});
|
||||||
|
std.debug.warn("\tscritcher run path_to_script.scri path_to_input_file.bmp\n", .{});
|
||||||
|
std.debug.warn("\tscritcher repl path_to_script.scri path_to_input_file.bmp\n", .{});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
// const allocator = std.heap.page_allocator;
|
// const allocator = std.heap.page_allocator;
|
||||||
var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){};
|
var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
@ -248,11 +255,16 @@ pub fn main() !void {
|
||||||
|
|
||||||
// TODO print help
|
// TODO print help
|
||||||
_ = args_it.skip();
|
_ = args_it.skip();
|
||||||
const cli_command = try (args_it.next(allocator) orelse @panic("expected 'run', 'help', or 'repl'"));
|
const cli_command_opt = args_it.next(allocator);
|
||||||
|
if (cli_command_opt == null) {
|
||||||
|
return doHelp();
|
||||||
|
}
|
||||||
|
|
||||||
|
const cli_command = try cli_command_opt.?;
|
||||||
defer allocator.free(cli_command);
|
defer allocator.free(cli_command);
|
||||||
|
|
||||||
if (std.mem.eql(u8, cli_command, "help")) {
|
if (std.mem.eql(u8, cli_command, "help")) {
|
||||||
//return try doHelp();
|
return doHelp();
|
||||||
} else if (std.mem.eql(u8, cli_command, "repl")) {
|
} else if (std.mem.eql(u8, cli_command, "repl")) {
|
||||||
return try doRepl(allocator, &args_it);
|
return try doRepl(allocator, &args_it);
|
||||||
} else if (std.mem.eql(u8, cli_command, "run")) {
|
} else if (std.mem.eql(u8, cli_command, "run")) {
|
||||||
|
@ -274,6 +286,7 @@ pub fn main() !void {
|
||||||
|
|
||||||
try runner.runCommands(cmds, true);
|
try runner.runCommands(cmds, true);
|
||||||
} else {
|
} else {
|
||||||
@panic("expected 'run', 'help', or 'repl'");
|
std.debug.warn("unknown command: '{s}'\n", .{cli_command});
|
||||||
|
return error.UnknownCommand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue