better helpmenue for clean && show possible subfunction with invlaid subfunctioninput

This commit is contained in:
Markus 2019-08-21 18:39:35 +02:00
parent 3080d4102d
commit 67d9d8c832
2 changed files with 22 additions and 16 deletions

View File

@ -39,14 +39,21 @@ int manageParameter(Settings &settings, int argc, char **argv)
return 1; return 1;
} }


int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]); std::vector<std::string> res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]);
if(res != 1) { if(res.size() != 1) {
std::cout << " => Error: " << ( (res == 0) ? std::string("Unbekannte Unteroption: '") + argv[1] + "'" : if(res.size() == 0)
std::string("Mehrere Optionen für '") + argv[1] + std::string("' gefunden.") ) << std::endl; std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl; else if(res.size() > 1) {
std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl; std::cout << " => Error: Mehrere Unteroptionen für '" << argv[1] << "' gefunden:" << std::endl;
return 2; for (auto &e : res)
std::cout << " > '" << argv[1] << "' =? " << e << std::endl;
}
std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl;
return 2;
} }
res.clear();



if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) { if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
argv[1][0] = '\0'; argv[1][0] = '\0';
@ -242,9 +249,6 @@ int loadDefaulOptions(Settings &settings)
} }
} }





ifs.close(); ifs.close();
return 0; return 0;
} }
@ -889,8 +893,8 @@ void unterOption_clean(Settings * settings, int argc, char **argv)
{ {
if(argc > 2) if(argc > 2)
if(strncmp("--help", argv[2], strlen(argv[2])) == 0) { if(strncmp("--help", argv[2], strlen(argv[2])) == 0) {
std::cout << "Aufruf: " << getProgramName() << " clean" << std::endl << std::endl; std::cout << "Aufruf: " << getProgramName() << "clean\n " << getProgramName() << "clean --help" << std::endl << std::endl
std::cout << "Mit dieser Function werden die Cookie-Files gelöscht." << std::endl; << "Beschreibung:" << std::endl << " Mit dieser Unterfunction kann man die Cookie-Dateien löschen." << std::endl << std::endl;
return; return;
} }


@ -921,14 +925,15 @@ void unterOption_clean(Settings * settings, int argc, char **argv)
} }




int compare(std::string All_Options_with_komma_between, std::string input) std::vector<std::string> compare(std::string All_Options_with_komma_between, std::string input)
{ {
std::istringstream iStrStream( All_Options_with_komma_between + "\n"); std::istringstream iStrStream( All_Options_with_komma_between + "\n");
std::string line; std::string line;
int allFounds = 0; std::vector<std::string> allFounds;

while (getline(iStrStream, line).good()) while (getline(iStrStream, line).good())
if(strncmp(line.c_str(), input.c_str(), input.length()) == 0) { if(strncmp(line.c_str(), input.c_str(), input.length()) == 0) {
allFounds++; allFounds.push_back(line);
//std::cout << "Unteroption '" << input << "' stimmt mit '" << line << "' überein." << std::endl; //std::cout << "Unteroption '" << input << "' stimmt mit '" << line << "' überein." << std::endl;
} }
return allFounds; return allFounds;

View File

@ -9,6 +9,7 @@
#include <fstream> #include <fstream>
#include <limits.h> // PATH_MAX #include <limits.h> // PATH_MAX
#include <unistd.h> // readlink() #include <unistd.h> // readlink()
#include <vector>


#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -61,7 +62,7 @@ struct Settings {


int manageParameter(Settings &settings, int argc, char ** argv); int manageParameter(Settings &settings, int argc, char ** argv);
int loadDefaulOptions(Settings & settings); int loadDefaulOptions(Settings & settings);
int compare(std::string All_Options_with_komma_between, std::string input); std::vector<std::string> compare(std::string All_Options_with_komma_between, std::string input);


std::string getProgramName(); std::string getProgramName();
std::string getexepath(); std::string getexepath();