aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-01-21 12:11:47 -0500
committerJack Lloyd <[email protected]>2018-01-21 12:11:47 -0500
commit935a1ccd64891065d0092249c569e965ee30b4c1 (patch)
tree1a6c4b40dca717f42ea05a2428d8090f87865eef
parent25d5cc16886f60f4f0d36009c9f057628b6905fe (diff)
Fix a bug in command line handling
If --help was provided to a command line that required at least one argument (such as hmac), a usage error would be shown before the help output. But we should not require any arguments if the --help option is given since no arguments will be used in that case.
-rw-r--r--src/cli/argparse.h21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/cli/argparse.h b/src/cli/argparse.h
index ebedfefb1..1b61d8676 100644
--- a/src/cli/argparse.h
+++ b/src/cli/argparse.h
@@ -151,19 +151,22 @@ void Argument_Parser::parse_args(const std::vector<std::string>& params)
}
}
+ if(flag_set("help"))
+ return;
+
+ if(args.size() < m_spec_args.size())
+ {
+ // not enough arguments
+ throw CLI_Usage_Error("Invalid argument count, got " +
+ std::to_string(args.size()) +
+ " expected " +
+ std::to_string(m_spec_args.size()));
+ }
+
bool seen_stdin_flag = false;
size_t arg_i = 0;
for(auto const& arg : m_spec_args)
{
- if(arg_i >= args.size())
- {
- // not enough arguments
- throw CLI_Usage_Error("Invalid argument count, got " +
- std::to_string(args.size()) +
- " expected " +
- std::to_string(m_spec_args.size()));
- }
-
m_user_args.insert(std::make_pair(arg, args[arg_i]));
if(args[arg_i] == "-")