improve error message if argument for --config is missing

This commit is contained in:
2024-09-10 08:47:13 +02:00
parent a41eed98bb
commit 1efad3d45c

View File

@@ -20,7 +20,8 @@ pub fn main() !void {
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, ArgumentError.MissingAuthenticatorParam, //
ArgumentError.MissingConfigLocation,
=> { => {
// 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)
}, },
@@ -62,14 +63,14 @@ fn mainInternal() !void {
fn printHelp() void { fn printHelp() void {
const msg = const msg =
\\Usage: zig-totp command [options] \\Usage: zig-totp [command] [options]
\\ \\
\\Commands: \\Commands:
\\ list List the configured authentiators \\ list List the configured authentiators
\\ show NAME Show the code for the authenticator with name NAME \\ show NAME Show the code for the authenticator with name NAME
\\ \\
\\Options: \\Options:
\\ --config path The path to a config file (default is $XDG_CONFIG_HOME/zig-totp or $HOME/.zig-totp). \\ --config [path] The path to a config file (default is $XDG_CONFIG_HOME/zig-totp or $HOME/.zig-totp).
\\ \\
; ;
std.debug.print("{s}", .{msg}); std.debug.print("{s}", .{msg});
@@ -181,6 +182,7 @@ fn parseArgs(allocator: Allocator, args: []const []const u8) !Args {
if (eql(u8, "--config", arg)) { if (eql(u8, "--config", arg)) {
i += 1; i += 1;
if (i >= args.len) { if (i >= args.len) {
std.debug.print("expected a path after parameter '--config'\n see 'zig-totp' for help\n", .{});
return error.MissingConfigLocation; return error.MissingConfigLocation;
} }
result.config_location = args[i]; result.config_location = args[i];