[glom-postgresql-setup] helper: Check the command-line options and make this translatable.



commit 218ae2b4a3cfdd95862ff501f3fec2adb503cb1e
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Oct 11 10:53:24 2011 +0200

    helper: Check the command-line options and make this translatable.
    
    * src/glom-postgresql-setup-helper.cc: Make the command-line options
    descriptions translatable and mention them as the main group when doing
    --help.
    Check that none of the inputs are empty.
    This gives people a clue about how this executable works.
    * po/POTFILES.in: Mention the file.

 ChangeLog                           |   11 ++++++++
 po/POTFILES.in                      |    1 +
 src/glom-postgresql-setup-helper.cc |   44 +++++++++++++++++++++++++++++-----
 3 files changed, 49 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6ad5357..b9c509b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-10-11  Murray Cumming  <murrayc murrayc com>
 
+	helper: Check the command-line options and make this translatable.
+
+	* src/glom-postgresql-setup-helper.cc: Make the command-line options
+	descriptions translatable and mention them as the main group when doing
+	--help.
+	Check that none of the inputs are empty.
+	This gives people a clue about how this executable works.
+	* po/POTFILES.in: Mention the file.
+
+2011-10-11  Murray Cumming  <murrayc murrayc com>
+
 	Add AUTHORS, COPYING, README, NEWS
 
 	* configure.ac: Remove the foreign option from the AM_INIT_AUTOMAKE 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 72b1ef6..f566d07 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,3 +1,4 @@
 org.gnome.glom.policy.in.in
 glom-postgresql-setup.desktop.in.in
 src/config-dialog.cc
+src/glom-postgresql-setup-helper.cc
diff --git a/src/glom-postgresql-setup-helper.cc b/src/glom-postgresql-setup-helper.cc
index 2dda680..5319781 100644
--- a/src/glom-postgresql-setup-helper.cc
+++ b/src/glom-postgresql-setup-helper.cc
@@ -46,6 +46,8 @@
 #include <string.h>
 #include <errno.h>
 
+#include <glibmm/i18n.h>
+
 // The value of port should be extracted from the config file
 // and then used in the database connection string.
 static int port = -1;
@@ -292,34 +294,60 @@ int main(int argc, char *argv[])
   Glib::ustring password;
   Glib::ustring config_path;
 
-  Glib::OptionGroup options("glom_setup", "Glom setup options");
+  Glib::OptionGroup options("glom_setup", _("Glom PostgreSQL setup options"));
 
   Glib::OptionEntry username_option;
   username_option.set_long_name("username");
-  username_option.set_description("Username of new PostgreSQL user.");
+  username_option.set_description(_("Username of new PostgreSQL user."));
   options.add_entry(username_option, username);
 
   Glib::OptionEntry password_option;
   password_option.set_long_name("password");
-  password_option.set_description("Password of new PostgreSQL user.");
+  password_option.set_description(_("Password of new PostgreSQL user."));
   options.add_entry(password_option, password);
 
   Glib::OptionEntry config_path_option;
   config_path_option.set_long_name("config-path");
-  config_path_option.set_description("Postgresql configuration file path of new PostgreSQL user.");
+  config_path_option.set_description(_("PostgreSQL configuration file path."));
   options.add_entry(config_path_option, config_path);
 
   Glib::OptionContext context;
-  context.add_group(options);
+  context.set_main_group(options);
+  
 
   // Make Sure we've got a username and password.
+  bool parse_failed = false;
   try
   {
     context.parse(argc, argv);
   }
   catch(const Glib::Error&)
   {
-    print_error_msg("ERROR: Could not parse arguments");
+    print_error_msg("ERROR: Could not parse arguments.");
+    parse_failed = true;
+  }
+
+  if(username.empty())
+  {
+    print_error_msg("ERROR: no PostgreSQL username was provided.");
+    parse_failed = true;
+  }
+
+  if(password.empty())
+  {
+    print_error_msg("ERROR: no PostgreSQL password was provided.");
+    parse_failed = true;
+  }
+
+  if(config_path.empty())
+  {
+    print_error_msg("ERROR: no PostgreSQL configuration file path was provided.");
+    parse_failed = true;
+  }
+
+  if(parse_failed)
+  {
+    std::cerr << std::endl << context.get_help() << std::endl;
     return ErrorCodes::MISC_BAD_ARGUMENTS;
   }
 
@@ -327,10 +355,12 @@ int main(int argc, char *argv[])
   int config_exit_code = set_listen_on_all_interfaces(config_path);
   if(!(config_exit_code == SuccessCodes::CHANGES_APPLIED ||
        config_exit_code == SuccessCodes::CHANGES_NOT_NEEDED))
+  {
     return config_exit_code;
+  }
 
   // Create new user.
-  int create_user_exit_code = create_postgre_user(username, password);
+  const int create_user_exit_code = create_postgre_user(username, password);
 
   return create_user_exit_code;
 }



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