mirror of
https://github.com/sbrow/envr.git
synced 2026-06-28 02:58:33 -04:00
wip: feat: Migrated deps command.
This commit is contained in:
96
src/main.zig
96
src/main.zig
@@ -14,11 +14,15 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
|
|
||||||
const args = try init.minimal.args.toSlice(arena);
|
const args = try init.minimal.args.toSlice(arena);
|
||||||
|
|
||||||
run(init.io, args) catch return fallback_to_go(init.io, arena, args);
|
try run(init.io, init.environ_map, args); //catch return fallback_to_go(init.io, arena, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to run the requested command.
|
/// Attempt to run the requested command.
|
||||||
fn run(io: Io, args: []const [:0]const u8) !void {
|
fn run(
|
||||||
|
io: Io,
|
||||||
|
environ_map: *std.process.Environ.Map,
|
||||||
|
args: []const [:0]const u8,
|
||||||
|
) !void {
|
||||||
const cmd = try envr.root.parse(args[1..]);
|
const cmd = try envr.root.parse(args[1..]);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
.envr => {
|
.envr => {
|
||||||
@@ -32,6 +36,17 @@ fn run(io: Io, args: []const [:0]const u8) !void {
|
|||||||
|
|
||||||
return version(stdout_writer);
|
return version(stdout_writer);
|
||||||
},
|
},
|
||||||
|
.deps => {
|
||||||
|
var stdout_buffer: [1024]u8 = undefined;
|
||||||
|
var stdout_file_writer: Io.File.Writer = .init(.stdout(), io, &stdout_buffer);
|
||||||
|
const stdout_writer = &stdout_file_writer.interface;
|
||||||
|
|
||||||
|
return deps(
|
||||||
|
io,
|
||||||
|
stdout_writer,
|
||||||
|
environ_map.get("PATH").?,
|
||||||
|
);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +55,83 @@ fn version(writer: *Io.Writer) !void {
|
|||||||
try writer.flush();
|
try writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display dependency statuses
|
||||||
|
fn deps(
|
||||||
|
io: Io,
|
||||||
|
writer: *Io.Writer,
|
||||||
|
path: []const u8,
|
||||||
|
) !void {
|
||||||
|
var feats: Features = .{};
|
||||||
|
|
||||||
|
// try writer.print("path: {s}\n\n", .{path});
|
||||||
|
|
||||||
|
var dirs = std.mem.splitScalar(u8, path, std.fs.path.delimiter);
|
||||||
|
|
||||||
|
// std.debug.print("feats: {b}\n", .{@as(u2, @bitCast(feats))});
|
||||||
|
// std.debug.print("all feats: {b}\n", .{@as(u2, @bitCast(Features.all_features))});
|
||||||
|
|
||||||
|
loop: while (dirs.next()) |dir| {
|
||||||
|
// try writer.print("dir: {s}\n", .{dir});
|
||||||
|
// try writer.flush();
|
||||||
|
|
||||||
|
// FIXME: Need to handle this failure
|
||||||
|
const dirt = try Io.Dir.openDir(Io.Dir.cwd(), io, dir, .{ .follow_symlinks = true, .iterate = true });
|
||||||
|
defer dirt.close(io);
|
||||||
|
|
||||||
|
var dir_paths = dirt.iterate();
|
||||||
|
|
||||||
|
while (try dir_paths.next(io)) |file| {
|
||||||
|
// FIXME: Check if executable
|
||||||
|
// switch (file.kind) {
|
||||||
|
// .file, .sym_link => {
|
||||||
|
if (std.mem.eql(u8, std.fs.path.basename(file.name), "git")) {
|
||||||
|
feats.git = true;
|
||||||
|
// try writer.print("file: {s}\n", .{file.name});
|
||||||
|
// try writer.flush();
|
||||||
|
|
||||||
|
if (feats == Features.all_features) {
|
||||||
|
break :loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std.mem.eql(u8, std.fs.path.basename(file.name), "fd")) {
|
||||||
|
feats.fd = true;
|
||||||
|
// try writer.print("file: {s}\n", .{file.name});
|
||||||
|
// try writer.flush();
|
||||||
|
|
||||||
|
if (feats == Features.all_features) {
|
||||||
|
break :loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// },
|
||||||
|
|
||||||
|
// else => {},
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (path_contains(path, "git")) {
|
||||||
|
// feats.git = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (path_contains(path, "fd")) {
|
||||||
|
// feats.fd = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
try writer.print("features: {}", .{feats});
|
||||||
|
try writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Features = packed struct {
|
||||||
|
git: bool = false,
|
||||||
|
fd: bool = false,
|
||||||
|
const all_features: Features = .{
|
||||||
|
.git = true,
|
||||||
|
.fd = true,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
fn fallback_to_go(
|
fn fallback_to_go(
|
||||||
io: Io,
|
io: Io,
|
||||||
arena: std.mem.Allocator,
|
arena: std.mem.Allocator,
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ const Command = comma.Command;
|
|||||||
|
|
||||||
pub const root: Command = .new(.{
|
pub const root: Command = .new(.{
|
||||||
.name = "envr",
|
.name = "envr",
|
||||||
.subcommands = &.{.{ .name = "version" }},
|
.subcommands = &.{
|
||||||
|
.{ .name = "deps" },
|
||||||
|
.{ .name = "version" },
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
test "enum type" {
|
test "enum type" {
|
||||||
|
|||||||
Reference in New Issue
Block a user