From a41eed98bb07387651cac5c2fa8c0ab796cac773 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 9 Sep 2024 19:01:20 +0200 Subject: [PATCH] better error message when there is no parameter after 'show' --- src/main.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index 5a329b0..30881ab 100644 --- a/src/main.zig +++ b/src/main.zig @@ -19,7 +19,9 @@ pub fn main() !void { Base32Error.InvalidCharacter, Base32Error.InvalidPadding => { try std.io.getStdErr().writer().print("The secret is invalid.\n", .{}); }, - ArgumentError.UnknownParameter => { + ArgumentError.UnknownParameter, // + ArgumentError.MissingAuthenticatorParam, + => { // do nothing, error message is already written (because the message contains the name of the unknown parameter) }, ArgumentError.InvalidOtpAuthUrl => {}, @@ -164,7 +166,7 @@ fn zeroPad(allocator: Allocator, digits: u4, x: anytype) ![]u8 { return result; } -const ArgumentError = error{ InvalidOtpAuthUrl, UnknownParameter, MissingConfigLocation, AuthenticatorNotFound }; +const ArgumentError = error{ InvalidOtpAuthUrl, UnknownParameter, MissingConfigLocation, AuthenticatorNotFound, MissingAuthenticatorParam }; fn parseArgs(allocator: Allocator, args: []const []const u8) !Args { var result = Args{ @@ -187,7 +189,8 @@ fn parseArgs(allocator: Allocator, args: []const []const u8) !Args { } else if (eql(u8, "show", arg)) { i += 1; if (i >= args.len) { - return error.MissingConfigLocation; + std.debug.print("expected authenticator name after command 'show'\n get a list of available authenticators with 'zig-totp list'\n", .{}); + return error.MissingAuthenticatorParam; } result.show = args[i]; } else {