aboutsummaryrefslogtreecommitdiff
path: root/binaries/rd/rd.zig
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-02-20 11:42:21 +0530
committerBobby <[email protected]>2026-02-20 11:42:21 +0530
commitcbadff7321682914e9473134d838b2c268fb6afd (patch)
treeb5d29d4c11ac0c9147b23bebbf26ce5e06c02d07 /binaries/rd/rd.zig
parent98d2a091f675f2bf6987098ffe11f765835459c0 (diff)
downloadakiba-cbadff7321682914e9473134d838b2c268fb6afd.tar.xz
akiba-cbadff7321682914e9473134d838b2c268fb6afd.zip
feat: Implement parameter parsing library and integrate into existing binaries
Diffstat (limited to 'binaries/rd/rd.zig')
-rw-r--r--binaries/rd/rd.zig30
1 files changed, 25 insertions, 5 deletions
diff --git a/binaries/rd/rd.zig b/binaries/rd/rd.zig
index 008cb54..882de3c 100644
--- a/binaries/rd/rd.zig
+++ b/binaries/rd/rd.zig
@@ -3,20 +3,40 @@
const colors = @import("colors");
const format = @import("format");
const io = @import("io");
+const params = @import("params");
const sys = @import("sys");
var file_buffer: [64 * 1024]u8 = undefined;
export fn main(pc: u32, pv: [*]const [*:0]const u8) u8 {
- if (pc <= 1) {
+ const p = params.parse(pc, pv) catch |err| {
+ format.color("rd: ", colors.red);
+ format.println(@errorName(err));
+ return 1;
+ };
+
+ if (p.positionals.len == 0) {
format.colorln("rd: missing unit location.", colors.red);
return 1;
}
- const arg = pv[1];
- var location_len: usize = 0;
- while (arg[location_len] != 0) : (location_len += 1) {}
- const location = arg[0..location_len];
+ if (p.positionals.len > 1) {
+ format.colorln("rd: invalid number of positional parameters.", colors.red);
+ return 1;
+ }
+
+ if (p.named.len > 0) {
+ format.colorln("rd: named parameters are not supported.", colors.red);
+ return 1;
+ }
+
+ const location = switch (p.positional(0).?) {
+ .scalar => |s| s,
+ .list => {
+ format.colorln("rd: only one location allowed", colors.red);
+ return 1;
+ },
+ };
const fd = io.attach(location, io.VIEW_ONLY) catch {
format.color("rd: cannot access '", colors.red);