lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master f241d25 7/7: Make CLI and GUI getopt code mor


From: Greg Chicares
Subject: [lmi-commits] [lmi] master f241d25 7/7: Make CLI and GUI getopt code more similar
Date: Mon, 4 Mar 2019 12:06:41 -0500 (EST)

branch: master
commit f241d25e6195bae6c4b5ab077fc882b975135cc2
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Make CLI and GUI getopt code more similar
    
    Removed pointless boolean flags. If an option performs an imperative
    action, it's simpler to inline that action's code in the option handler.
    
    Removed an accidental '-b' option. It was apparently just a placeholder
    in the original implementation, which had never been removed until now.
    
    Made all options that are documented "...and exit" actually return (some
    had not done so). Immediate-return options return 0 in the CLI; in the
    GUI, they return nonzero, merely because that's a convenient way to tell
    wx to exit.
---
 main_cli.cpp | 69 +++++++++++++++---------------------------------------------
 skeleton.cpp | 17 ++++++---------
 2 files changed, 23 insertions(+), 63 deletions(-)

diff --git a/main_cli.cpp b/main_cli.cpp
index e495448..4f6e0ec 100644
--- a/main_cli.cpp
+++ b/main_cli.cpp
@@ -181,11 +181,6 @@ void process_command_line(int argc, char* argv[])
       };
 
     bool license_accepted    = false;
-    bool show_license        = false;
-    bool show_help           = false;
-    bool run_selftest        = false;
-    bool run_profile         = false;
-    bool print_all_databases = false;
 
     mcenum_emission emission(mce_emit_nothing);
 
@@ -282,12 +277,6 @@ void process_command_line(int argc, char* argv[])
                 }
                 break;
 
-            case 'b':
-                {
-                std::printf("option b\n");
-                }
-                break;
-
             case 'd':
                 {
                 global_settings::instance().set_data_directory
@@ -359,37 +348,48 @@ void process_command_line(int argc, char* argv[])
 
             case 'h':
                 {
-                show_help = true;
+                getopt_long.usage();
+                std::cout << "Suboptions for '--emit':\n";
+                for(auto const& i : allowed_strings_emission())
+                    {
+                    std::cout << "  " << i << '\n';
+                    }
+                return;
                 }
                 break;
 
             case 'l':
                 {
-                show_license = true;
+                std::cerr << license_as_text() << "\n\n";
+                return;
                 }
                 break;
 
             case 'o':
                 {
-                run_profile = true;
+                profile();
+                return;
                 }
                 break;
 
             case 'p':
                 {
-                print_all_databases = true;
+                print_databases();
+                return;
                 }
                 break;
 
             case 's':
                 {
-                run_selftest = true;
+                self_test();
+                return;
                 }
                 break;
 
             case 't':
                 {
-                print_all_databases = true;
+                print_databases();
+                return;
                 }
                 break;
 
@@ -430,41 +430,6 @@ void process_command_line(int argc, char* argv[])
         std::cerr << license_notices_as_text() << "\n\n";
         }
 
-    if(show_license)
-        {
-        std::cerr << license_as_text() << "\n\n";
-        return;
-        }
-
-    if(show_help)
-        {
-        getopt_long.usage();
-        std::cout << "Suboptions for '--emit':\n";
-        for(auto const& i : allowed_strings_emission())
-            {
-            std::cout << "  " << i << '\n';
-            }
-        return;
-        }
-
-    if(run_selftest)
-        {
-        self_test();
-        return;
-        }
-
-    if(run_profile)
-        {
-        profile();
-        return;
-        }
-
-    if(print_all_databases)
-        {
-        print_databases();
-        return;
-        }
-
     std::for_each
         (illustrator_names.begin()
         ,illustrator_names.end()
diff --git a/skeleton.cpp b/skeleton.cpp
index f1e7c26..74da643 100644
--- a/skeleton.cpp
+++ b/skeleton.cpp
@@ -1207,8 +1207,6 @@ bool Skeleton::ProcessCommandLine()
         {0              ,NO_ARG   ,0 ,0   ,0 ,""}
       };
 
-    bool show_help = false;
-
     std::vector<std::string> input_files;
 
     int option_index = 0;
@@ -1277,19 +1275,24 @@ bool Skeleton::ProcessCommandLine()
 
             case 'h':
                 {
-                show_help = true;
+                std::ostringstream oss;
+                getopt_long.usage(oss);
+                wxMessageBox(oss.str(), "Command-line options");
+                return false;
                 }
                 break;
 
             case 'p':
                 {
                 print_databases();
+                return false;
                 }
                 break;
 
             case 't':
                 {
                 print_databases();
+                return false;
                 }
                 break;
 
@@ -1337,14 +1340,6 @@ bool Skeleton::ProcessCommandLine()
         warning() << std::flush;
         }
 
-    if(show_help)
-        {
-        std::ostringstream oss;
-        getopt_long.usage(oss);
-        wxMessageBox(oss.str(), "Command-line options");
-        return false;
-        }
-
     if(!input_files.empty())
         {
         // Can't open files until main window is initialized.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]