From 13633f715d84a972e9626336b28e9ec0a1411af3 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 24 Jan 2017 06:58:45 +0100 Subject: [PATCH] fix(main): Exit on unrecognized positional arg --- src/components/command_line.cpp | 4 ++-- src/main.cpp | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/command_line.cpp b/src/components/command_line.cpp index 6f83eb64..859c0710 100644 --- a/src/components/command_line.cpp +++ b/src/components/command_line.cpp @@ -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] : ""; } /** diff --git a/src/main.cpp b/src/main.cpp index 1965b6bb..a38ddeab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; }