diff --git a/include/Arguments.hpp b/include/Arguments.hpp index 126bd52..8341f20 100644 --- a/include/Arguments.hpp +++ b/include/Arguments.hpp @@ -120,6 +120,9 @@ class Arguments /// Zip archive about which to display information std::optional infoArchive; + /// Tell whether version information is needed or not + bool version = false; + /// Tell whether help message is needed or not bool help = false; @@ -157,6 +160,7 @@ class Arguments jobs, exhaustive, infoArchive, + version, help }; diff --git a/src/Arguments.cpp b/src/Arguments.cpp index 1ab7dc0..06e8934 100644 --- a/src/Arguments.cpp +++ b/src/Arguments.cpp @@ -92,11 +92,8 @@ Arguments::Arguments(int argc, const char* argv[]) while(!finished()) parseArgument(); - if(help) - return; - - if(infoArchive) - return; + if(help || version || infoArchive) + return; // no further checks are needed for those options // check constraints on arguments if(keys) @@ -296,6 +293,9 @@ void Arguments::parseArgument() case Option::infoArchive: infoArchive = readString("zipfile"); break; + case Option::version: + version = true; + break; case Option::help: help = true; break; @@ -340,6 +340,7 @@ Arguments::Option Arguments::readOption(const std::string& description) PAIRS(-j, --jobs, jobs), PAIRS(-e, --exhaustive, exhaustive), PAIRS(-L, --list, infoArchive), + PAIR ( --version, version), PAIRS(-h, --help, help) }; diff --git a/src/main.cpp b/src/main.cpp index 9413aac..27ad970 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,6 +93,7 @@ Other options: passwords) instead of stopping after the first solution is found -L, --list List entries in a zip archive and exit + --version Show version information and exit -h, --help Show this help and exit)_"; void listEntries(const std::string& archiveFilename); @@ -116,6 +117,12 @@ try return 0; } + if(args.version) + { + // version information was already printed, nothing else to do + return 0; + } + if(args.infoArchive) { listEntries(*args.infoArchive); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3bb067a..f0e64bf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,5 +15,8 @@ set_tests_properties(cli.bruteforce.long PROPERTIES PASS_REGULAR_EXPRESSION "P add_test(NAME cli.list COMMAND bkcrack -L secrets.zip WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/example) set_tests_properties(cli.list PROPERTIES PASS_REGULAR_EXPRESSION "advice\.jpg.*spiral\.svg") +add_test(NAME cli.version COMMAND bkcrack --version) +set_tests_properties(cli.version PROPERTIES PASS_REGULAR_EXPRESSION "^bkcrack ${bkcrack_VERSION} - ${bkcrack_VERSION_DATE}\n\$") + add_test(NAME cli.help COMMAND bkcrack -h) set_tests_properties(cli.help PROPERTIES PASS_REGULAR_EXPRESSION "usage:")