From 55efe036dd3a98e74a3e5bac211b2534c7fc249e Mon Sep 17 00:00:00 2001 From: zvon Date: Wed, 9 Jan 2019 22:19:47 +0100 Subject: [PATCH] Fixed command line options --- tv_rename.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tv_rename.cpp b/tv_rename.cpp index e0454bb..a53aaf7 100644 --- a/tv_rename.cpp +++ b/tv_rename.cpp @@ -51,7 +51,7 @@ void parseSeasonNumbers(std::set &seasons_num, const char *argument) { } } -bool parseCommandLine(std::string &show, std::set &seasons_num, std::string &path, bool &change_dir, int argc, char **argv) { +int parseCommandLine(std::string &show, std::set &seasons_num, std::string &path, bool &change_dir, int argc, char **argv) { static struct option long_options[] = { {"show", required_argument, 0, 's' }, {"season", required_argument, 0, 'n' }, @@ -60,9 +60,8 @@ bool parseCommandLine(std::string &show, std::set &seasons_num, std::string {"trust", no_argument, 0, 't' }, {"linux", no_argument, 0, 'x' }, {"lang", required_argument, 0, 'l' }, - {"print-langs", no_argument, 0, 0 }, - {"help", no_argument, 0, 'h' }, - {0, 0, 0, 0 } + {"print-langs", no_argument, 0, '0' }, + {"help", no_argument, 0, 'h' } }; while(1) { @@ -97,21 +96,21 @@ bool parseCommandLine(std::string &show, std::set &seasons_num, std::string } else { std::cerr << "Invalid language choice" << std::endl; printLangs(); - return false; + return -1; } break; case '0': printLangs(); - return true; + return 1; case 'h': printHelp(); - return true; + return 1; default: - return false; + return -1; } } - return true; + return 0; } int main(int argc, char** argv) { @@ -120,8 +119,13 @@ int main(int argc, char** argv) { std::string path{"."}; bool change_dir{true}; - if( !parseCommandLine(show, seasons_num, path, change_dir, argc, argv) ) - return 1; + { + auto tmp = parseCommandLine(show, seasons_num, path, change_dir, argc, argv); + if( tmp == -1 ) + return 1; + else if ( tmp == 1 ) + return 0; + } if( !FSLib::isDirectory(path) ) change_dir = true;