Compare commits
No commits in common. "e5373cb143e0ea81fa68a00aff03c235f2e55ab5" and "37f16a03b703d8dc42fa77cc812d03bbd8e104b7" have entirely different histories.
e5373cb143
...
37f16a03b7
2 changed files with 6 additions and 52 deletions
|
|
@ -4,6 +4,10 @@
|
|||
.fingerprint = 0xb88932861fde7cb9,
|
||||
.minimum_zig_version = "0.15.2",
|
||||
.dependencies = .{
|
||||
.flags = .{
|
||||
.url = "git+https://github.com/neurocyte/flags?ref=main#984b27948da3e4e40a253f76c85b51ec1a9ada11",
|
||||
.hash = "flags-0.10.0-a_9h3gB4AADAYn0XaZuUqH1jKRmy6dqvAIbomtTIF6V1",
|
||||
},
|
||||
.@"xcode-frameworks" = .{
|
||||
.url = "git+https://github.com/hexops/xcode-frameworks?ref=main#8a1cfb373587ea4c9bb1468b7c986462d8d4e10e",
|
||||
.hash = "N-V-__8AALShqgXkvqYU6f__FrA22SMWmi2TXCJjNTO1m8XJ",
|
||||
|
|
|
|||
54
src/main.zig
54
src/main.zig
|
|
@ -17,7 +17,6 @@ fn posix_sighandler(_: c_int) callconv(.c) void {
|
|||
const CliHandler = struct {
|
||||
handler: nightwatch.Handler,
|
||||
out: std.fs.File,
|
||||
ignore: []const []const u8,
|
||||
|
||||
const vtable = nightwatch.Handler.VTable{
|
||||
.change = change_cb,
|
||||
|
|
@ -27,9 +26,6 @@ const CliHandler = struct {
|
|||
|
||||
fn change_cb(h: *nightwatch.Handler, path: []const u8, event_type: nightwatch.EventType, object_type: nightwatch.ObjectType) error{HandlerFailed}!void {
|
||||
const self: *CliHandler = @fieldParentPtr("handler", h);
|
||||
for (self.ignore) |ignored| {
|
||||
if (std.mem.eql(u8, path, ignored)) return;
|
||||
}
|
||||
var buf: [4096]u8 = undefined;
|
||||
var stdout = self.out.writer(&buf);
|
||||
defer stdout.interface.flush() catch {};
|
||||
|
|
@ -49,9 +45,6 @@ const CliHandler = struct {
|
|||
|
||||
fn rename_cb(h: *nightwatch.Handler, src: []const u8, dst: []const u8, object_type: nightwatch.ObjectType) error{HandlerFailed}!void {
|
||||
const self: *CliHandler = @fieldParentPtr("handler", h);
|
||||
for (self.ignore) |ignored| {
|
||||
if (std.mem.eql(u8, src, ignored) or std.mem.eql(u8, dst, ignored)) return;
|
||||
}
|
||||
var buf: [4096]u8 = undefined;
|
||||
var stdout = self.out.writer(&buf);
|
||||
defer stdout.interface.flush() catch {};
|
||||
|
|
@ -113,14 +106,10 @@ fn usage(out: std.fs.File) !void {
|
|||
var buf: [4096]u8 = undefined;
|
||||
var writer = out.writer(&buf);
|
||||
try writer.interface.print(
|
||||
\\Usage: nightwatch [--ignore <path>]... <path> [<path> ...]
|
||||
\\Usage: nightwatch <path> [<path> ...]
|
||||
\\
|
||||
\\The Watch never sleeps.
|
||||
\\
|
||||
\\Options:
|
||||
\\ --ignore <path> Suppress events whose path exactly matches <path>.
|
||||
\\ May be specified multiple times.
|
||||
\\
|
||||
\\Events printed to stdout (columns: event type path):
|
||||
\\ create a file or directory was created
|
||||
\\ modify a file was modified
|
||||
|
|
@ -156,44 +145,6 @@ pub fn main() !void {
|
|||
var stderr = std.fs.File.stderr().writer(&buf);
|
||||
defer stderr.interface.flush() catch {};
|
||||
|
||||
// Parse --ignore options and watch paths.
|
||||
// Ignored paths are made absolute (without resolving symlinks) so they
|
||||
// match the absolute paths the backend emits in event callbacks.
|
||||
var ignore_list = std.ArrayListUnmanaged([]const u8){};
|
||||
defer {
|
||||
for (ignore_list.items) |p| allocator.free(p);
|
||||
ignore_list.deinit(allocator);
|
||||
}
|
||||
var watch_paths = std.ArrayListUnmanaged([]const u8){};
|
||||
defer watch_paths.deinit(allocator);
|
||||
|
||||
var cwd_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
const cwd = try std.fs.cwd().realpath(".", &cwd_buf);
|
||||
|
||||
var i: usize = 1;
|
||||
while (i < args.len) : (i += 1) {
|
||||
if (std.mem.eql(u8, args[i], "--ignore")) {
|
||||
i += 1;
|
||||
if (i >= args.len) {
|
||||
try stderr.interface.print("nightwatch: --ignore requires an argument\n", .{});
|
||||
std.process.exit(1);
|
||||
}
|
||||
const raw = args[i];
|
||||
const abs = if (std.fs.path.isAbsolute(raw))
|
||||
try allocator.dupe(u8, raw)
|
||||
else
|
||||
try std.fs.path.join(allocator, &.{ cwd, raw });
|
||||
try ignore_list.append(allocator, abs);
|
||||
} else {
|
||||
try watch_paths.append(allocator, args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (watch_paths.items.len == 0) {
|
||||
try usage(std.fs.File.stderr());
|
||||
std.process.exit(1);
|
||||
}
|
||||
|
||||
if (is_posix) {
|
||||
sig_pipe = try std.posix.pipe();
|
||||
const sa = std.posix.Sigaction{
|
||||
|
|
@ -212,13 +163,12 @@ pub fn main() !void {
|
|||
var cli_handler = CliHandler{
|
||||
.handler = .{ .vtable = &CliHandler.vtable },
|
||||
.out = std.fs.File.stdout(),
|
||||
.ignore = ignore_list.items,
|
||||
};
|
||||
|
||||
var watcher = try nightwatch.init(allocator, &cli_handler.handler);
|
||||
defer watcher.deinit();
|
||||
|
||||
for (watch_paths.items) |path| {
|
||||
for (args[1..]) |path| {
|
||||
watcher.watch(path) catch |err| {
|
||||
try stderr.interface.print("nightwatch: {s}: {s}\n", .{ path, @errorName(err) });
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue