fix(main): Exit on unrecognized positional arg
This commit is contained in:
parent
d6a34717bf
commit
13633f715d
@ -86,7 +86,7 @@ namespace command_line {
|
||||
* Test if a positional argument is defined at given index
|
||||
*/
|
||||
bool parser::has(size_t index) const {
|
||||
return m_posargs.size() >= std::max(1_z, index);
|
||||
return m_posargs.size() > index;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ namespace command_line {
|
||||
* Get the positional argument at given index
|
||||
*/
|
||||
string parser::get(size_t index) const {
|
||||
return has(index) ? m_posargs[std::max(1_z, index) - 1] : "";
|
||||
return has(index) ? m_posargs[index] : "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +98,11 @@ int main(int argc, char** argv) {
|
||||
string confpath;
|
||||
|
||||
// Make sure a bar name is passed in
|
||||
if (!cli->has(1)) {
|
||||
if (!cli->has(0)) {
|
||||
cli->usage();
|
||||
return EXIT_FAILURE;
|
||||
} else if (cli->has(1)) {
|
||||
fprintf(stderr, "Unrecognized argument \"%s\"\n", cli->get(1).c_str());
|
||||
cli->usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user