Bugfix, -l option now works

This commit is contained in:
King_DuckZ 2013-08-23 22:15:18 +02:00
parent cb1f4fffd9
commit aad2501499
2 changed files with 40 additions and 15 deletions

View file

@ -11,7 +11,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(PROJ_VER_MAJOR "0") set(PROJ_VER_MAJOR "0")
set(PROJ_VER_MINOR "1") set(PROJ_VER_MINOR "1")
set(PROJ_VER_REVISION "1") set(PROJ_VER_REVISION "2")
get_git_head_revision(GIT_REFSPEC PROJ_GIT_SHA1) get_git_head_revision(GIT_REFSPEC PROJ_GIT_SHA1)
configure_file ( configure_file (

View file

@ -47,7 +47,20 @@ namespace {
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
///------------------------------------------------------------------------ ///------------------------------------------------------------------------
bool GetCommandLine (boost::program_options::variables_map& parVarMap, int parArgc, const char* const parArgv[]) { void ShowVersion() {
std::cout << APP_NAME << " v" << APP_VER_MAJOR << "." << APP_VER_MINOR << "." << APP_VER_REVISION << "\n";
std::cout << "rev: " << APP_VER_GIT << "\n";
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
void ShowHelp (const boost::program_options::options_description& parDesc) {
std::cout << parDesc << "\n";
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
bool GetCommandLine (boost::program_options::variables_map& parVarMap, int parArgc, const char* const parArgv[], const std::vector<const char*>& parOverrideArgs) {
const char* const programName = parArgv[0]; const char* const programName = parArgv[0];
std::ostringstream oss; std::ostringstream oss;
oss << "Usage is " << GetBaseName(parArgv[0]) << " [options] <from language> <to language> <search term>; parameters"; oss << "Usage is " << GetBaseName(parArgv[0]) << " [options] <from language> <to language> <search term>; parameters";
@ -76,20 +89,31 @@ namespace {
boost::program_options::notify(parVarMap); boost::program_options::notify(parVarMap);
bool shownSomething = false; bool shownSomething = false;
if (parVarMap.count("version") == 0) {
const bool enoughParams = static_cast<bool>( const bool enoughParams = static_cast<bool>(
parVarMap.count("source-lang") == 1 and parVarMap.count("source-lang") == 1 and
parVarMap.count("dest-lang") == 1 and parVarMap.count("dest-lang") == 1 and
parVarMap.count("word") > 0 parVarMap.count("word") > 0
); );
if (parVarMap.count("help") or not enoughParams) { bool ignoreFewerParams = false;
std::cout << desc << "\n"; if (parVarMap.count("help")) {
ShowHelp(desc);
shownSomething = true; shownSomething = true;
} }
else if (parVarMap.count("version")) {
ShowVersion();
shownSomething = true;
} }
else { else {
std::cout << APP_NAME << " v" << APP_VER_MAJOR << "." << APP_VER_MINOR << "." << APP_VER_REVISION << "\n"; for (std::vector<const char*>::const_iterator itCur = parOverrideArgs.begin(), itCurEND = parOverrideArgs.end(); itCur != itCurEND; ++itCur) {
std::cout << "rev: " << APP_VER_GIT << "\n"; if (parVarMap.count(*itCur)) {
ignoreFewerParams = true;
break;
}
}
}
if (not (shownSomething or ignoreFewerParams or enoughParams)) {
ShowHelp(desc);
shownSomething = true; shownSomething = true;
} }
return shownSomething; return shownSomething;
@ -102,7 +126,8 @@ int main (int parArgc, const char* const parArgv[]) {
//std::setlocale(LC_CTYPE, "UTF-8"); //std::setlocale(LC_CTYPE, "UTF-8");
std::setlocale(LC_CTYPE, ""); std::setlocale(LC_CTYPE, "");
boost::program_options::variables_map vm; boost::program_options::variables_map vm;
if (GetCommandLine(vm, parArgc, parArgv)) const std::vector<const char*> paramsSkipCompulsoryInput = {"listlanguages"};
if (GetCommandLine(vm, parArgc, parArgv, paramsSkipCompulsoryInput))
return 0; return 0;
if (vm.count("listlanguages")) { if (vm.count("listlanguages")) {