[gvfs] gvfs-move: Fix cmd-line help and error reporting



commit b7cf5c8aab80aa43eca9b9603bc76483f847d288
Author: Christian Kellner <gicmo gnome org>
Date:   Thu Feb 18 17:26:08 2010 +0100

    gvfs-move: Fix cmd-line help and error reporting
    
    Partly fixes bug #593045

 programs/gvfs-move.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/programs/gvfs-move.c b/programs/gvfs-move.c
index ae8a3fe..7d7114b 100644
--- a/programs/gvfs-move.c
+++ b/programs/gvfs-move.c
@@ -69,6 +69,19 @@ show_progress (goffset current_num_bytes,
 	   current_num_bytes, total_num_bytes);
 }
 
+static void
+show_help (GOptionContext *context, const char *error)
+{
+  char *help;
+
+  if (error)
+    g_printerr (_("Error: %s"), error);
+
+  help = g_option_context_get_help (context, TRUE, NULL);
+  g_printerr ("%s", help);
+  g_free (help);
+  g_option_context_free (context);
+}
 
 int
 main (int argc, char *argv[])
@@ -86,10 +99,9 @@ main (int argc, char *argv[])
   g_type_init ();
 
   error = NULL;
-  context = g_option_context_new (_("- output files at <location>"));
+  context = g_option_context_new (_("SOURCE... DEST - move file(s) from SOURCE to DEST"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
   g_option_context_parse (context, &argc, &argv, &error);
-  g_option_context_free (context);
 
   if (error != NULL)
     {
@@ -104,7 +116,7 @@ main (int argc, char *argv[])
 
   if (argc <= 2)
     {
-      g_printerr (_("Missing operand\n"));
+      show_help (context, _("Missing operand\n"));
       return 1;
     }
 
@@ -112,7 +124,7 @@ main (int argc, char *argv[])
 
   if (no_target_directory && argc > 3)
     {
-      g_printerr (_("Too many arguments\n"));
+      show_help (context, _("Too many arguments\n"));
       g_object_unref (dest);
       return 1;
     }
@@ -122,10 +134,13 @@ main (int argc, char *argv[])
   if (!dest_is_dir && argc > 3)
     {
       g_printerr (_("Target %s is not a directory\n"), argv[argc-1]);
+      show_help (context, NULL);
       g_object_unref (dest);
       return 1;
     }
 
+  g_option_context_free (context);
+
   for (i = 1; i < argc - 1; i++)
     {
       source = g_file_new_for_commandline_arg (argv[i]);



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