mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor: Moved deps into root.zig.
This commit is contained in:
2
.envrc
2
.envrc
@@ -1,4 +1,4 @@
|
||||
use flake
|
||||
|
||||
ROOT="/home/spencer/Desktop/envr"
|
||||
ROOT="."
|
||||
export PATH=".:${ROOT}/deps/zig:${ROOT}/deps/zls:$PATH"
|
||||
|
||||
59
src/main.zig
59
src/main.zig
@@ -44,7 +44,7 @@ fn run(
|
||||
var stdout_file_writer: Io.File.Writer = .init(.stdout(), io, &stdout_buffer);
|
||||
const stdout_writer = &stdout_file_writer.interface;
|
||||
|
||||
return deps(
|
||||
return envr.deps(
|
||||
io,
|
||||
stdout_writer,
|
||||
environ_map.get("PATH").?,
|
||||
@@ -75,63 +75,6 @@ fn version(writer: *Io.Writer) !void {
|
||||
try writer.flush();
|
||||
}
|
||||
|
||||
// Display dependency statuses
|
||||
fn deps(
|
||||
io: Io,
|
||||
writer: *Io.Writer,
|
||||
path: []const u8,
|
||||
) !void {
|
||||
const feats: Features = try .scan(io, path);
|
||||
|
||||
// FIXME: Draw as a table
|
||||
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,
|
||||
};
|
||||
|
||||
/// Scans your PATH variable for programs.
|
||||
pub fn scan(io: Io, path: []const u8) !@This() {
|
||||
var feats: Features = .{};
|
||||
|
||||
var dirs = std.mem.splitScalar(u8, path, std.fs.path.delimiter);
|
||||
|
||||
loop: while (dirs.next()) |dir| {
|
||||
const dirt = Io.Dir.openDir(Io.Dir.cwd(), io, dir, .{ .follow_symlinks = true, .iterate = true }) catch continue;
|
||||
defer dirt.close(io);
|
||||
|
||||
var dir_paths = dirt.iterate();
|
||||
|
||||
while (try dir_paths.next(io)) |file| {
|
||||
// FIXME: Check if executable
|
||||
if (std.mem.eql(u8, std.fs.path.basename(file.name), "git")) {
|
||||
feats.git = true;
|
||||
|
||||
if (feats == Features.all_features) {
|
||||
break :loop;
|
||||
}
|
||||
}
|
||||
|
||||
if (std.mem.eql(u8, std.fs.path.basename(file.name), "fd")) {
|
||||
feats.fd = true;
|
||||
|
||||
if (feats == Features.all_features) {
|
||||
break :loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return feats;
|
||||
}
|
||||
};
|
||||
|
||||
fn fallback_to_go(
|
||||
io: Io,
|
||||
arena: std.mem.Allocator,
|
||||
|
||||
57
src/root.zig
57
src/root.zig
@@ -63,6 +63,63 @@ pub const root: Command = .new(.{
|
||||
},
|
||||
});
|
||||
|
||||
// Display dependency statuses
|
||||
pub fn deps(
|
||||
io: Io,
|
||||
writer: *Io.Writer,
|
||||
path: []const u8,
|
||||
) !void {
|
||||
const feats: Features = try .scan(io, path);
|
||||
|
||||
// FIXME: Draw as a table
|
||||
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,
|
||||
};
|
||||
|
||||
/// Scans your PATH variable for programs.
|
||||
pub fn scan(io: Io, path: []const u8) !@This() {
|
||||
var feats: Features = .{};
|
||||
|
||||
var dirs = std.mem.splitScalar(u8, path, std.fs.path.delimiter);
|
||||
|
||||
loop: while (dirs.next()) |dir| {
|
||||
const dirt = Io.Dir.openDir(Io.Dir.cwd(), io, dir, .{ .follow_symlinks = true, .iterate = true }) catch continue;
|
||||
defer dirt.close(io);
|
||||
|
||||
var dir_paths = dirt.iterate();
|
||||
|
||||
while (try dir_paths.next(io)) |file| {
|
||||
// FIXME: Check if executable
|
||||
if (std.mem.eql(u8, std.fs.path.basename(file.name), "git")) {
|
||||
feats.git = true;
|
||||
|
||||
if (feats == Features.all_features) {
|
||||
break :loop;
|
||||
}
|
||||
}
|
||||
|
||||
if (std.mem.eql(u8, std.fs.path.basename(file.name), "fd")) {
|
||||
feats.fd = true;
|
||||
|
||||
if (feats == Features.all_features) {
|
||||
break :loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return feats;
|
||||
}
|
||||
};
|
||||
|
||||
pub fn list(
|
||||
io: Io,
|
||||
arena: std.mem.Allocator,
|
||||
|
||||
Reference in New Issue
Block a user