Compare commits

..

No commits in common. "69ac3fa6a6a0c7f2a9ec7ef67c96cd47e9768855" and "3040b77bff64c271efc0d0a04a9c19bba5b2f3a6" have entirely different histories.

4 changed files with 26 additions and 74 deletions

View file

@ -205,11 +205,11 @@
"xdph": "xdph" "xdph": "xdph"
}, },
"locked": { "locked": {
"lastModified": 1712835979, "lastModified": 1712586782,
"narHash": "sha256-m44SvLfwPc8qPpBQa5ObOtTe6RbVNfQLpn+bCdlHFxQ=", "narHash": "sha256-8/JkRxsXLhiGELcw7t5RBf1mk94mbHc/oJiBzoPYTv8=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "Hyprland", "repo": "Hyprland",
"rev": "185a3b48814cc4a1afbf32a69792a6161c4038cd", "rev": "63e3668529f6c06478ec288723d0ba46374c4bc5",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -385,11 +385,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1712757991, "lastModified": 1712573573,
"narHash": "sha256-kR7C7Fqt3JP40h0mzmSZeWI5pk1iwqj4CSeGjnUbVHc=", "narHash": "sha256-xxon7WwNm4/EadMKg1eF40/5s0O78nXUy2ILZt6vT7E=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d6b3ddd253c578a7ab98f8011e59990f21dc3932", "rev": "0d28066770464d19d637f6e8e42e8688420b6ac6",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -424,11 +424,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1712844911, "lastModified": 1712589286,
"narHash": "sha256-HByQWVHn0sG7BFj+7z9UhhMY9CcCqaWBPXX5H3QKRyQ=", "narHash": "sha256-pyppS3qgeZagY/YZF0ug2rf97Z91+gaUwnS0McFuH1k=",
"owner": "nix-community", "owner": "nix-community",
"repo": "nixpkgs-wayland", "repo": "nixpkgs-wayland",
"rev": "ed9ef02d368c00e69e8e67fa86d0226559df75aa", "rev": "2547cb5b49297ad22dee07f6847c7a99a99f7721",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -490,11 +490,11 @@
}, },
"stable": { "stable": {
"locked": { "locked": {
"lastModified": 1712741485, "lastModified": 1712437997,
"narHash": "sha256-bCs0+MSTra80oXAsnM6Oq62WsirOIaijQ/BbUY59tR4=", "narHash": "sha256-g0whLLwRvgO2FsyhY8fNk+TWenS3jg5UdlWL4uqgFeo=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b2cf36f43f9ef2ded5711b30b1f393ac423d8f72", "rev": "e38d7cb66ea4f7a0eb6681920615dfcc30fc2920",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -691,11 +691,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1712798505, "lastModified": 1712539287,
"narHash": "sha256-eWGnAesSlXa7E2ugjwPT7g1HVs0uPPoLL2NT9sOzKCU=", "narHash": "sha256-TIcl3dKFqSymIFUj3vRN05Ahl2eAH/EqJRf/P5nCBtY=",
"owner": "Cloudef", "owner": "Cloudef",
"repo": "zig2nix", "repo": "zig2nix",
"rev": "c5279639cbbb10df20a340f54dd95b562fafc552", "rev": "53e12c1a03c34b0b35bcb0eb5b495ba90f62302f",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -3,13 +3,9 @@ const std = @import("std");
const yazap = @import("yazap"); const yazap = @import("yazap");
const App = yazap.App; const App = yazap.App;
const Arg = yazap.Arg; const Arg = yazap.Arg;
const Allocator = std.mem.Allocator;
allocator: Allocator, const Allocator = std.mem.Allocator;
app: App, app: App,
matches: *const yazap.ArgMatches = undefined,
forward: ?[][]const u8 = null,
process_args: ?[]const [:0]u8 = null,
pub fn init(allocator: Allocator) !Cli { pub fn init(allocator: Allocator) !Cli {
var app = App.init(allocator, "oizys", "nix begat oizys"); var app = App.init(allocator, "oizys", "nix begat oizys");
@ -21,55 +17,19 @@ pub fn init(allocator: Allocator) !Cli {
var cmd_output = app.createCommand("output", "show system flake output path"); var cmd_output = app.createCommand("output", "show system flake output path");
var cmd_boot = app.createCommand("boot", "nixos rebuild boot"); var cmd_boot = app.createCommand("boot", "nixos rebuild boot");
var cmd_switch = app.createCommand("switch", "nixos rebuild switch"); var cmd_switch = app.createCommand("switch", "nixos rebuild switch");
const commands = .{ &cmd_dry, &cmd_build, &cmd_cache, &cmd_output, &cmd_switch, &cmd_boot };
try cmd_cache.addArg(Arg.singleValueOption("name", 'n', "name of cachix cache")); try cmd_cache.addArg(Arg.singleValueOption("name", 'n', "name of cachix cache"));
inline for (.{ inline for (commands) |subcmd| {
&cmd_dry,
&cmd_build,
&cmd_cache,
&cmd_output,
&cmd_switch,
&cmd_boot,
}) |subcmd| {
try subcmd.addArg(Arg.positional("forward", null, null));
try subcmd.addArg(Arg.singleValueOption("flake", 'f', "path to flake")); try subcmd.addArg(Arg.singleValueOption("flake", 'f', "path to flake"));
try subcmd.addArg(Arg.singleValueOption("host", null, "hostname (default: current host)")); try subcmd.addArg(Arg.singleValueOption("host", null, "hostname (default: current host)"));
try subcmd.addArg(Arg.booleanOption("no-pinix", null, "don't use pinix")); try subcmd.addArg(Arg.booleanOption("no-pinix", null, "don't use pinix"));
try oizys.addSubcommand(subcmd.*); try oizys.addSubcommand(subcmd.*);
} }
return Cli{ return Cli{ .app = app };
.allocator = allocator,
.app = app,
};
}
fn get_forward_args(self: *Cli, args: []const [:0]u8) !usize {
var forward = std.ArrayList([]const u8).init(self.allocator);
const delim_idx: usize = delim_lookup: for (args, 0..) |arg, i| {
if (std.mem.eql(u8, "--", arg)) break :delim_lookup i;
} else args.len;
if (args.len > delim_idx)
for (args[delim_idx + 1 ..]) |fwd|
try forward.append(fwd);
self.forward = try forward.toOwnedSlice();
return delim_idx;
}
pub fn parse(self: *Cli) !void {
self.process_args = try std.process.argsAlloc(self.allocator);
const delim_idx = try self.get_forward_args(self.process_args.?);
self.matches = try self.app.parseFrom(self.process_args.?[1..delim_idx]);
} }
pub fn deinit(self: *Cli) void { pub fn deinit(self: *Cli) void {
std.process.argsFree(self.allocator, self.process_args.?);
if (self.forward) |fwd| {
for (fwd) |arg| self.allocator.free(arg);
self.allocator.free(fwd);
}
self.app.deinit(); self.app.deinit();
} }

View file

@ -11,7 +11,6 @@ output: []const u8,
cmd: OizysCmd, cmd: OizysCmd,
no_pinix: bool, no_pinix: bool,
debug: bool = false, debug: bool = false,
forward: ?[][]const u8,
pub const OizysCmd = enum { pub const OizysCmd = enum {
dry, dry,
@ -22,13 +21,11 @@ pub const OizysCmd = enum {
build, build,
}; };
pub fn init(allocator: std.mem.Allocator, matches: *const ArgMatches, forward: ?[][]const u8) !Oizys { pub fn init(allocator: std.mem.Allocator, matches: *const ArgMatches) !Oizys {
const cmd = matches.subcommand.?.name; const cmd = matches.subcommand.?.name;
const flags = matches.subcommandMatches(cmd).?; const flags = matches.subcommandMatches(cmd).?;
const host = flags.getSingleValue("host") orelse const host = flags.getSingleValue("host") orelse try Oizys.getDefaultHostName(allocator);
try Oizys.getDefaultHostName(allocator); const flake = flags.getSingleValue("flake") orelse try Oizys.getDefaultFlake(allocator);
const flake = flags.getSingleValue("flake") orelse
try Oizys.getDefaultFlake(allocator);
return Oizys{ return Oizys{
.allocator = allocator, .allocator = allocator,
@ -42,7 +39,6 @@ pub fn init(allocator: std.mem.Allocator, matches: *const ArgMatches, forward: ?
.cmd = std.meta.stringToEnum(OizysCmd, cmd).?, .cmd = std.meta.stringToEnum(OizysCmd, cmd).?,
.cache_name = flags.getSingleValue("cache") orelse "daylin", .cache_name = flags.getSingleValue("cache") orelse "daylin",
.no_pinix = flags.containsArg("no-pinix"), .no_pinix = flags.containsArg("no-pinix"),
.forward = forward,
}; };
} }
@ -93,7 +89,6 @@ pub fn runNixCmd(self: *Oizys, cmd: NixCmd, argv: []const []const u8) !void {
NixCmd.NixosRebuild => try args.appendSlice(&.{ "sudo", self.nixos_rebuild() }), NixCmd.NixosRebuild => try args.appendSlice(&.{ "sudo", self.nixos_rebuild() }),
} }
try args.appendSlice(argv); try args.appendSlice(argv);
if (self.forward) |fwd| try args.appendSlice(fwd);
var p = std.ChildProcess.init(args.items, self.allocator); var p = std.ChildProcess.init(args.items, self.allocator);
_ = try p.spawnAndWait(); _ = try p.spawnAndWait();
} }
@ -132,8 +127,7 @@ pub fn run(self: *Oizys) !void {
try self.runNixCmd(NixCmd.Nix, &.{ "build", self.output }); try self.runNixCmd(NixCmd.Nix, &.{ "build", self.output });
}, },
.output => { .output => {
const stdout = std.io.getStdOut().writer(); std.debug.print("{s}", .{self.output});
try stdout.print("{s}\n", .{self.output});
}, },
.cache => { .cache => {
try self.cache(); try self.cache();

View file

@ -9,16 +9,14 @@ pub fn main() !void {
const allocator = arena.allocator(); const allocator = arena.allocator();
var cli = try Cli.init(allocator); var cli = try Cli.init(allocator);
try cli.parse(); const matches = try cli.app.parseProcess();
defer cli.deinit();
if (!cli.matches.containsArgs()) { if (!matches.containsArgs()) {
try cli.app.displayHelp(); try cli.app.displayHelp();
return; return;
} }
var oizys = try Oizys.init(allocator, cli.matches, cli.forward); var oizys = try Oizys.init(allocator, matches);
defer oizys.deinit();
try oizys.run(); try oizys.run();
} }