|
| 1 | +const builtin = @import("builtin"); |
| 2 | +const clap = @import("clap"); |
| 3 | +const std = @import("std"); |
| 4 | +const ziggybox = @import("ziggybox"); |
| 5 | + |
| 6 | +fn umount(path: [*:0]const u8) !void { |
| 7 | + const r = std.os.linux.umount(path); |
| 8 | + return switch (std.os.errno(r)) { |
| 9 | + .SUCCESS => {}, |
| 10 | + .PERM => error.AccessDenied, |
| 11 | + else => |err| return std.os.unexpectedErrno(err), |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | +pub fn run(args: *std.process.ArgIterator) !void { |
| 16 | + const stderr = ziggybox.io.getStdErr(); |
| 17 | + |
| 18 | + const params = comptime clap.parseParamsComptime( |
| 19 | + \\-h, --help Display this help and exit. |
| 20 | + \\<path> The directory to unmount |
| 21 | + \\ |
| 22 | + ); |
| 23 | + |
| 24 | + var diag = clap.Diagnostic{}; |
| 25 | + var res = ziggybox.clap.parseEx(clap.Help, ¶ms, comptime .{ |
| 26 | + .path = clap.parsers.string, |
| 27 | + }, args, .{ |
| 28 | + .allocator = ziggybox.common.allocator, |
| 29 | + .diagnostic = &diag, |
| 30 | + }) catch |err| { |
| 31 | + diag.report(stderr, err) catch {}; |
| 32 | + return err; |
| 33 | + }; |
| 34 | + defer res.deinit(); |
| 35 | + |
| 36 | + if (res.args.help != 0 or res.positionals.len < 1) |
| 37 | + return clap.help(stderr, clap.Help, ¶ms, .{}); |
| 38 | + |
| 39 | + const path = try ziggybox.common.allocator.dupeZ(u8, res.positionals[0]); |
| 40 | + defer ziggybox.common.allocator.free(path); |
| 41 | + try umount(path); |
| 42 | +} |
0 commit comments