improve error message if argument for --config is missing
This commit is contained in:
@@ -20,7 +20,8 @@ pub fn main() !void {
|
||||
try std.io.getStdErr().writer().print("The secret is invalid.\n", .{});
|
||||
},
|
||||
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)
|
||||
},
|
||||
@@ -62,14 +63,14 @@ fn mainInternal() !void {
|
||||
|
||||
fn printHelp() void {
|
||||
const msg =
|
||||
\\Usage: zig-totp command [options]
|
||||
\\Usage: zig-totp [command] [options]
|
||||
\\
|
||||
\\Commands:
|
||||
\\ list List the configured authentiators
|
||||
\\ show NAME Show the code for the authenticator with name NAME
|
||||
\\
|
||||
\\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});
|
||||
@@ -181,6 +182,7 @@ fn parseArgs(allocator: Allocator, args: []const []const u8) !Args {
|
||||
if (eql(u8, "--config", arg)) {
|
||||
i += 1;
|
||||
if (i >= args.len) {
|
||||
std.debug.print("expected a path after parameter '--config'\n see 'zig-totp' for help\n", .{});
|
||||
return error.MissingConfigLocation;
|
||||
}
|
||||
result.config_location = args[i];
|
||||
|
||||
Reference in New Issue
Block a user