[ostree: 4/6] fix --help for static-delta



commit ed2b56a43059ef061eb405a9b1cb788d1ac4e62a
Author: Giuseppe Scrivano <gscrivan redhat com>
Date:   Thu Oct 30 14:23:34 2014 +0100

    fix --help for static-delta
    
    Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>

 src/ostree/ot-builtin-static-delta.c |   83 ++++++++++++++++++++++-----------
 tests/test-delta.sh                  |    2 +-
 2 files changed, 56 insertions(+), 29 deletions(-)
---
diff --git a/src/ostree/ot-builtin-static-delta.c b/src/ostree/ot-builtin-static-delta.c
index f2d9a83..b133c4c 100644
--- a/src/ostree/ot-builtin-static-delta.c
+++ b/src/ostree/ot-builtin-static-delta.c
@@ -47,6 +47,7 @@ static OstreeCommand static_delta_subcommands[] = {
   { NULL, NULL }
 };
 
+
 static GOptionEntry generate_options[] = {
   { "from", 0, 0, G_OPTION_ARG_STRING, &opt_from_rev, "Create delta from revision REV", "REV" },
   { "to", 0, 0, G_OPTION_ARG_STRING, &opt_to_rev, "Create delta to revision REV", "REV" },
@@ -56,6 +57,14 @@ static GOptionEntry generate_options[] = {
   { NULL }
 };
 
+static GOptionEntry apply_offline_options[] = {
+  { NULL }
+};
+
+static GOptionEntry list_options[] = {
+  { NULL }
+};
+
 static void
 static_delta_usage (char    **argv,
                     gboolean  is_error)
@@ -68,8 +77,7 @@ static_delta_usage (char    **argv,
   else
     print_func = g_print;
 
-  print_func ("usage: %s --repo=PATH static-delta\n",
-              argv[0]);
+  print_func ("usage: ostree static-delta\n");
   print_func ("Builtin commands:\n");
 
   while (command->name)
@@ -88,8 +96,9 @@ ot_static_delta_builtin_list (int argc, char **argv, GCancellable *cancellable,
   GOptionContext *context;
   gs_unref_object OstreeRepo *repo = NULL;
 
-  context = g_option_context_new ("LIST - list delta files");
-  if (!ostree_option_context_parse (context, NULL, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
+  context = g_option_context_new ("LIST - list static delta files");
+
+  if (!ostree_option_context_parse (context, list_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
     goto out;
 
   if (!ostree_repo_list_static_delta_names (repo, &delta_names, cancellable, error))
@@ -125,10 +134,10 @@ ot_static_delta_builtin_generate (int argc, char **argv, GCancellable *cancellab
   if (!ostree_option_context_parse (context, generate_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, 
&repo, cancellable, error))
     goto out;
 
-  if (argc >= 2 && opt_to_rev == NULL)
-    opt_to_rev = argv[1];
+  if (argc >= 3 && opt_to_rev == NULL)
+    opt_to_rev = argv[2];
 
-  if (argc < 2 && opt_to_rev == NULL)
+  if (argc < 3 && opt_to_rev == NULL)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "TO revision must be specified");
@@ -208,18 +217,18 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, GCancellable *canc
   GOptionContext *context;
   gs_unref_object OstreeRepo *repo = NULL;
 
-  context = g_option_context_new ("DELTA - Apply delta file");
-  if (!ostree_option_context_parse (context, NULL, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
+  context = g_option_context_new ("DELTA - Apply static delta file");
+  if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, 
&repo, cancellable, error))
     goto out;
 
-  if (argc < 2)
+  if (argc < 3)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "PATH must be specified");
       goto out;
     }
 
-  patharg = argv[1];
+  patharg = argv[2];
   path = g_file_new_for_path (patharg);
 
   if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
@@ -242,30 +251,50 @@ gboolean
 ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, GError **error)
 {
   gboolean ret = FALSE;
-  OstreeCommand *command;
-  const char *cmdname;
-  GOptionContext *context;
+  OstreeCommand *command = NULL;
+  const char *cmdname = NULL;
   gs_unref_object OstreeRepo *repo = NULL;
+  int i;
+  gboolean want_help = FALSE;
 
-  context = g_option_context_new ("DELTA - Apply delta file");
-  if (!ostree_option_context_parse (context, NULL, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
-    goto out;
+  for (i = 1; i < argc; i++)
+    {
+      if (argv[i][0] != '-')
+        {
+          cmdname = argv[i];
+          break;
+        }
+      else if (g_str_equal (argv[i], "--help") || g_str_equal (argv[i], "-h"))
+        {
+          want_help = TRUE;
+          break;
+        }
+    }
 
-  if (argc < 2)
+  if (!cmdname && !want_help)
     {
       static_delta_usage (argv, TRUE);
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "No command specified");
       goto out;
     }
-  
-  cmdname = argv[1];
-  command = static_delta_subcommands;
-  while (command->name)
+
+  if (cmdname)
     {
-      if (g_strcmp0 (cmdname, command->name) == 0)
-        break;
-      command++;
+      command = static_delta_subcommands;
+      while (command->name)
+        {
+          if (g_strcmp0 (cmdname, command->name) == 0)
+            break;
+          command++;
+        }
+    }
+
+  if (want_help && command == NULL)
+    {
+      static_delta_usage (argv, FALSE);
+      ret = TRUE;
+      goto out;
     }
 
   if (!command->fn)
@@ -276,12 +305,10 @@ ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, G
       goto out;
     }
 
-  if (!command->fn (argc-1, argv+1, cancellable, error))
+  if (!command->fn (argc, argv, cancellable, error))
     goto out;
 
   ret = TRUE;
  out:
-  if (context)
-    g_option_context_free (context);
   return ret;
 }
diff --git a/tests/test-delta.sh b/tests/test-delta.sh
index 29c59d9..175daec 100755
--- a/tests/test-delta.sh
+++ b/tests/test-delta.sh
@@ -57,7 +57,7 @@ function permuteDirectory() {
 
 permuteDirectory 1 files
 ostree --repo=repo commit -b test -s test --tree=dir=files
-ostree static-delta --repo=repo list
+ostree --repo=repo static-delta list
 
 origrev=$(ostree --repo=repo rev-parse test^)
 newrev=$(ostree --repo=repo rev-parse test)


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