Changes
4 changed files (+24/-28)
-
-
@@ -17,7 +17,7 @@const std = @import("std"); const clap = @import("clap"); const exit = @import("../exit.zig").exit; const ExitCode = @import("../exit.zig").ExitCode; const list = @import("./server/list.zig"); const Commands = enum {
-
@@ -37,7 +37,7 @@ \\* list ... List available Roon Server on network (alias: ls)\\ ); pub fn run(allocator: std.mem.Allocator, iter: *std.process.ArgIterator) !void { pub fn run(allocator: std.mem.Allocator, iter: *std.process.ArgIterator) ExitCode { var diag = clap.Diagnostic{}; var res = clap.parseEx(clap.Help, ¶ms, parser, iter, .{ .diagnostic = &diag,
-
@@ -45,21 +45,21 @@ .allocator = allocator,.terminating_positional = 0, }) catch |err| { diag.report(std.io.getStdErr().writer(), err) catch {}; return err; return ExitCode.incorrect_usage; }; defer res.deinit(); if (res.args.help > 0) { clap.help(std.io.getStdOut().writer(), clap.Help, ¶ms, .{}) catch {}; exit(.ok); return ExitCode.ok; } const command = res.positionals[0] orelse { clap.help(std.io.getStdErr().writer(), clap.Help, ¶ms, .{}) catch {}; exit(.incorrect_usage); return ExitCode.incorrect_usage; }; switch (command) { return switch (command) { .ls, .list => list.run(allocator, iter), } }; }
-
-
-
@@ -18,7 +18,7 @@ const std = @import("std");const clap = @import("clap"); const core = @import("core"); const exit = @import("../../exit.zig").exit; const ExitCode = @import("../../exit.zig").ExitCode; const OutputFormat = enum { text,
-
@@ -43,20 +43,20 @@ \\* tsv ... TSV (tab-separated values).\\ ); pub fn run(allocator: std.mem.Allocator, iter: *std.process.ArgIterator) noreturn { pub fn run(allocator: std.mem.Allocator, iter: *std.process.ArgIterator) ExitCode { var diag = clap.Diagnostic{}; var res = clap.parseEx(clap.Help, ¶ms, parser, iter, .{ .diagnostic = &diag, .allocator = allocator, }) catch |err| { diag.report(std.io.getStdErr().writer(), err) catch {}; exit(.incorrect_usage); return ExitCode.incorrect_usage; }; defer res.deinit(); if (res.args.help > 0) { clap.help(std.io.getStdOut().writer(), clap.Help, ¶ms, .{}) catch {}; exit(.ok); return ExitCode.ok; } const count = res.args.count orelse 3;
-
@@ -64,7 +64,7 @@ const wait = res.args.wait orelse 2;var scanner = core.ServerScanner.init(allocator) catch { // TODO: Create and return appropriate error code exit(.not_ok); return ExitCode.not_ok; }; defer scanner.deinit();
-
@@ -76,7 +76,7 @@ // TODO: Hide this under verbose flagstderr.print("Sending discovery request ({d})...\n", .{i + 1}) catch {}; scanner.scan(.{ .receive_window_ms = wait * 1_000 }) catch { // TODO: Create and return appropriate error code exit(.not_ok); return ExitCode.not_ok; }; }
-
@@ -91,14 +91,14 @@ server.value_ptr.http_port,server.value_ptr.version, }) catch { // TODO: Create and return appropriate error code exit(.not_ok); return ExitCode.not_ok; }; } }, .tsv => { if (res.args.header > 0) { stdout.writeAll("ID\tName\tIP address\tHTTP port\tVersion\n") catch { exit(.not_ok); return ExitCode.not_ok; }; } while (server_iter.next()) |server| {
-
@@ -111,11 +111,11 @@ server.value_ptr.http_port,server.value_ptr.version, }) catch { // TODO: Create and return appropriate error code exit(.not_ok); return ExitCode.not_ok; }; } }, } exit(.ok); return ExitCode.ok; }
-
-
-
@@ -21,7 +21,3 @@ ok = 0,not_ok = 1, incorrect_usage = 2, }; pub fn exit(code: ExitCode) noreturn { std.process.exit(@intFromEnum(code)); }
-
-
-
@@ -18,7 +18,7 @@ const std = @import("std");const clap = @import("clap"); const build_config = @import("build_config"); const exit = @import("./exit.zig").exit; const ExitCode = @import("./exit.zig").ExitCode; const server = @import("./commands/server.zig"); const version = "0.0.0";
-
@@ -42,7 +42,7 @@ \\* server ... Lists or gets information of Roon Server on network\\ ); pub fn main() !void { pub fn main() !u8 { var arena = std.heap.ArenaAllocator.init( if (build_config.calloc) std.heap.c_allocator else std.heap.page_allocator, );
-
@@ -63,25 +63,25 @@ .allocator = allocator,.terminating_positional = 0, }) catch |err| { diag.report(std.io.getStdErr().writer(), err) catch {}; exit(.incorrect_usage); return @intFromEnum(ExitCode.incorrect_usage); }; defer res.deinit(); if (res.args.help > 0) { clap.help(std.io.getStdOut().writer(), clap.Help, &global_params, .{}) catch {}; exit(.ok); return @intFromEnum(ExitCode.ok); } const command = res.positionals[0] orelse { clap.help(std.io.getStdErr().writer(), clap.Help, &global_params, .{}) catch {}; exit(.incorrect_usage); return @intFromEnum(ExitCode.incorrect_usage); }; switch (command) { .server => try server.run(allocator, &iter), .server => return @intFromEnum(server.run(allocator, &iter)), .version => { try std.fmt.format(std.io.getStdOut().writer(), "{s}\n", .{version}); exit(.ok); return @intFromEnum(ExitCode.ok); }, } }
-