From b4f82ebfda8e5edc55b87dd5bb0831d8232f2049 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sat, 8 Mar 2025 19:31:05 +0100 Subject: [PATCH] add option to show help --- src/main.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 3f093c0..e8e3437 100644 --- a/src/main.zig +++ b/src/main.zig @@ -88,13 +88,14 @@ fn printHelp() void { \\ eval "$(zig-totp --bash)" \\ to your ~/.bashrc \\ --config [path] The path to a config file (default is $XDG_CONFIG_HOME/zig-totp or $HOME/.zig-totp). + \\ --help Show this help \\ --version Print the version number \\ ; std.debug.print("{s}", .{msg}); } -const Args = struct { list: bool, show: ?[]const u8, config_location: []const u8, validateAuthenticator: ?[]const u8, validateCode: ?[]const u8, print_version: bool }; +const Args = struct { list: bool, show: ?[]const u8, config_location: []const u8, validateAuthenticator: ?[]const u8, validateCode: ?[]const u8, print_version: bool, show_help: bool }; const OtpAuthUrl = struct { name: []const u8, secretEncoded: []const u8, url: []const u8, period: u32, digits: u4, algorithm: []const u8 }; @@ -190,7 +191,7 @@ fn zeroPad(allocator: Allocator, digits: u4, x: anytype) ![]u8 { const ArgumentError = error{ InvalidOtpAuthUrl, UnknownParameter, MissingConfigLocation, AuthenticatorNotFound, MissingAuthenticatorParam, FailedToOpenConfigFile, TooManyParsinErrors }; fn parseArgs(allocator: Allocator, args: []const []const u8) !Args { - var result = Args{ .list = false, .show = null, .config_location = try configLocation(allocator), .validateAuthenticator = null, .validateCode = null, .print_version = false }; + var result = Args{ .list = false, .show = null, .config_location = try configLocation(allocator), .validateAuthenticator = null, .validateCode = null, .print_version = false, .show_help = false }; var i: u17 = 1; while (i < args.len) : (i += 1) { const arg = args[i]; @@ -224,6 +225,8 @@ fn parseArgs(allocator: Allocator, args: []const []const u8) !Args { return error.MissingConfigLocation; } result.config_location = args[i]; + } else if (eql(u8, "--help", arg) or eql(u8, "help", arg)) { + result.show_help = true; } else if (eql(u8, "--version", arg)) { result.print_version = true; } else if (eql(u8, "list", arg)) {