[ostree] core: Make argument parsing more robust against "lt-ostree" name



commit 6d9de916725f61bd35d7725008c81c52a03ad978
Author: Colin Walters <walters verbum org>
Date:   Mon May 14 11:31:53 2012 -0400

    core: Make argument parsing more robust against "lt-ostree" name
    
    When running uninstalled, we were parsing our argv[0] incorrectly.

 src/ostree/ot-main.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c
index 3bdc4b3..789b223 100644
--- a/src/ostree/ot-main.c
+++ b/src/ostree/ot-main.c
@@ -90,6 +90,8 @@ ostree_main (int    argc,
   char **cmd_argv = NULL;
   gboolean am_root;
   gboolean have_repo_arg;
+  const char *binname = NULL;
+  const char *slash = NULL;
   const char *cmd = NULL;
   const char *repo = NULL;
   GFile *repo_file = NULL;
@@ -118,9 +120,16 @@ ostree_main (int    argc,
   if (repo)
     repo_file = ot_gfile_new_for_path (repo);
 
-  cmd = strchr (argv[0], '-');
-  if (cmd)
+  slash = strrchr (argv[0], '/');
+  if (slash)
+    binname = slash+1;
+  else
+    binname = argv[0];
+
+  if (g_str_has_prefix (binname, "ostree-"))
     {
+      cmd = strchr (binname, '-');
+      g_assert (cmd);
       cmd += 1;
       arg_off = 1;
       if (have_repo_arg)
@@ -147,7 +156,8 @@ ostree_main (int    argc,
 
   if (!builtin->name)
     {
-      set_error_print_usage (&error, builtins, "Unknown command", argv);
+      ot_lfree char *msg = g_strdup_printf ("Unknown command '%s'", cmd);
+      set_error_print_usage (&error, builtins, msg, argv);
       goto out;
     }
 



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