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

[virt-tools-list] [virt-viewer] Use real binary name in help message



Now that we have 2 distinct binaries, remote-viewer and virt-viewer,
'PACKAGE' can no longer be used in error messages as the name of the
binary. This cause a small inconsistency when running
'remote-viewer --foobar' as the error message would be:
'Unknown option --foobar
Run 'virt-viewer --help' to see a full list of available command line options'

This commit makes sure we use argv[0] for this message.
Fixes rhbz#814150
---
 src/remote-viewer-main.c |  9 +++++----
 src/virt-viewer-main.c   | 13 ++++++++++---
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
index 156bd0b..a671c18 100644
--- a/src/remote-viewer-main.c
+++ b/src/remote-viewer-main.c
@@ -204,7 +204,6 @@ main(int argc, char **argv)
     gboolean controller = FALSE;
 #endif
     VirtViewerApp *app;
-    const char *help_msg = N_("Run '" PACKAGE " --help' to see a full list of available command line options");
     const GOptionEntry options [] = {
         { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
           remote_viewer_version, N_("Display version information"), NULL },
@@ -261,9 +260,11 @@ main(int argc, char **argv)
 #endif
     g_option_context_parse (context, &argc, &argv, &error);
     if (error) {
-        g_printerr("%s\n%s\n",
-                   error->message,
-                   gettext(help_msg));
+        char *basename;
+        basename = g_path_get_basename(argv[0]);
+        g_printerr(_("%s\nRun '%s --help' to see a full list of available command line options\n"),
+                   error->message, basename);
+        g_free(basename);
         g_error_free(error);
         goto cleanup;
     }
diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c
index c80949b..bf938c4 100644
--- a/src/virt-viewer-main.c
+++ b/src/virt-viewer-main.c
@@ -57,7 +57,8 @@ int main(int argc, char **argv)
     gboolean reconnect = FALSE;
     gboolean fullscreen = FALSE;
     VirtViewer *viewer = NULL;
-    const char *help_msg = N_("Run '" PACKAGE " --help' to see a full list of available command line options");
+    char *basename;
+    char *help_msg = NULL;
     const GOptionEntry options [] = {
         { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
           virt_viewer_version, N_("Display version information"), NULL },
@@ -95,6 +96,12 @@ int main(int argc, char **argv)
 
     g_set_application_name(_("Virt Viewer"));
 
+
+    basename = g_path_get_basename(argv[0]);
+    help_msg = g_strdup_printf(_("Run '%s --help' to see a full list of available command line options"),
+                               basename);
+    g_free(basename);
+
     /* Setup command line options */
     context = g_option_context_new (_("- Virtual machine graphical console"));
     g_option_context_add_main_entries (context, options, NULL);
@@ -108,8 +115,7 @@ int main(int argc, char **argv)
     g_option_context_parse (context, &argc, &argv, &error);
     if (error) {
         g_printerr("%s\n%s\n",
-                   error->message,
-                   gettext(help_msg));
+                   error->message, help_msg);
         g_error_free(error);
         goto cleanup;
     }
@@ -147,6 +153,7 @@ int main(int argc, char **argv)
         g_object_unref(viewer);
     g_free(uri);
     g_strfreev(args);
+    g_free(help_msg);
 
     return ret;
 }
-- 
1.7.11.2


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