wip: turbo-getent
This commit is contained in:
parent
8877c7d812
commit
6ae17fe99d
50
src/turbo-getent.zig
Normal file
50
src/turbo-getent.zig
Normal file
@ -0,0 +1,50 @@
|
||||
const std = @import("std");
|
||||
const io = std.io;
|
||||
const os = std.os;
|
||||
const fmt = std.fmt;
|
||||
|
||||
const flags = @import("flags.zig");
|
||||
|
||||
const usage =
|
||||
\\usage: turbo-getent [OPTION]... group|passwd [key...]
|
||||
\\
|
||||
\\ -h Print this help message and exit
|
||||
\\ --db=PATH Path to the database (default: /etc/turbonss/db.turbo)
|
||||
\\
|
||||
\\turbo-getent resolves group or passwd (a.k.a. user) entries from the
|
||||
\\database file. If one or more key arguments are provided, then only
|
||||
\\entries that match the supplied keys will be displayed. If no key is
|
||||
\\provided, all entries will be displayed.
|
||||
\\
|
||||
;
|
||||
|
||||
pub fn main() !void {
|
||||
// This line is here because of https://github.com/ziglang/zig/issues/7807
|
||||
const argv: []const [*:0]const u8 = os.argv;
|
||||
|
||||
const stderr = io.getStdErr().writer();
|
||||
const stdout = io.getStdOut().writer();
|
||||
|
||||
const return_code = execute(stdout, stderr, argv[1..]);
|
||||
os.exit(return_code);
|
||||
}
|
||||
|
||||
fn execute(
|
||||
stdout: anytype,
|
||||
stderr: anytype,
|
||||
argv: []const [*:0]const u8,
|
||||
) u8 {
|
||||
const myflags = flags.parse(argv, &[_]flags.Flag{
|
||||
.{ .name = "-h", .kind = .boolean },
|
||||
}) catch {
|
||||
stderr.writeAll(usage) catch {};
|
||||
return 1;
|
||||
};
|
||||
|
||||
if (myflags.boolFlag("-h")) {
|
||||
stdout.writeAll(usage) catch return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user