better error message when there is no parameter after 'show'

This commit is contained in:
2024-09-09 19:01:20 +02:00
parent c0704a604b
commit a41eed98bb

View File

@@ -19,7 +19,9 @@ pub fn main() !void {
Base32Error.InvalidCharacter, Base32Error.InvalidPadding => { Base32Error.InvalidCharacter, Base32Error.InvalidPadding => {
try std.io.getStdErr().writer().print("The secret is invalid.\n", .{}); 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) // do nothing, error message is already written (because the message contains the name of the unknown parameter)
}, },
ArgumentError.InvalidOtpAuthUrl => {}, ArgumentError.InvalidOtpAuthUrl => {},
@@ -164,7 +166,7 @@ fn zeroPad(allocator: Allocator, digits: u4, x: anytype) ![]u8 {
return result; 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 { fn parseArgs(allocator: Allocator, args: []const []const u8) !Args {
var result = Args{ var result = Args{
@@ -187,7 +189,8 @@ fn parseArgs(allocator: Allocator, args: []const []const u8) !Args {
} else if (eql(u8, "show", arg)) { } else if (eql(u8, "show", arg)) {
i += 1; i += 1;
if (i >= args.len) { 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]; result.show = args[i];
} else { } else {