change default scri path to 'run' cli command
This commit is contained in:
parent
9937365433
commit
32b01976d8
2 changed files with 26 additions and 19 deletions
43
src/main.zig
43
src/main.zig
|
@ -248,25 +248,32 @@ pub fn main() !void {
|
||||||
|
|
||||||
// TODO print help
|
// TODO print help
|
||||||
_ = args_it.skip();
|
_ = args_it.skip();
|
||||||
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path or 'repl'"));
|
const cli_command = try (args_it.next(allocator) orelse @panic("expected 'run', 'help', or 'repl'"));
|
||||||
defer allocator.free(scri_path);
|
defer allocator.free(cli_command);
|
||||||
|
|
||||||
if (std.mem.eql(u8, scri_path, "repl")) {
|
if (std.mem.eql(u8, cli_command, "help")) {
|
||||||
|
//return try doHelp();
|
||||||
|
} 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")) {
|
||||||
|
const scri_path = try (args_it.next(allocator) orelse @panic("run: expected scri path"));
|
||||||
|
defer allocator.free(scri_path);
|
||||||
|
|
||||||
|
var file = try std.fs.cwd().openFile(scri_path, .{});
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
|
// sadly, we read it all into memory. such is life
|
||||||
|
const total_bytes = try file.getEndPos();
|
||||||
|
|
||||||
|
var data = try allocator.alloc(u8, total_bytes);
|
||||||
|
defer allocator.free(data);
|
||||||
|
_ = try file.read(data);
|
||||||
|
|
||||||
|
var cmds = try lang.parse(data);
|
||||||
|
defer cmds.deinit();
|
||||||
|
|
||||||
|
try runner.runCommands(cmds, true);
|
||||||
|
} else {
|
||||||
|
@panic("expected 'run', 'help', or 'repl'");
|
||||||
}
|
}
|
||||||
|
|
||||||
var file = try std.fs.cwd().openFile(scri_path, .{});
|
|
||||||
defer file.close();
|
|
||||||
|
|
||||||
// sadly, we read it all into memory. such is life
|
|
||||||
const total_bytes = try file.getEndPos();
|
|
||||||
|
|
||||||
var data = try allocator.alloc(u8, total_bytes);
|
|
||||||
defer allocator.free(data);
|
|
||||||
_ = try file.read(data);
|
|
||||||
|
|
||||||
var cmds = try lang.parse(data);
|
|
||||||
defer cmds.deinit();
|
|
||||||
|
|
||||||
try runner.runCommands(cmds, true);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub const Runner = struct {
|
||||||
// 'scritcher repl ./script ./image'
|
// 'scritcher repl ./script ./image'
|
||||||
|
|
||||||
// ':0' should ALWAYS point to the image.
|
// ':0' should ALWAYS point to the image.
|
||||||
if (self.repl) index += 3 else index += 2;
|
if (self.repl) index += 4 else index += 3;
|
||||||
|
|
||||||
for (self.args) |arg, idx| {
|
for (self.args) |arg, idx| {
|
||||||
std.debug.warn("arg{d} = {s}\n", .{ idx, arg });
|
std.debug.warn("arg{d} = {s}\n", .{ idx, arg });
|
||||||
|
|
Loading…
Reference in a new issue