Refactor command-line parsing

Refactor command-line parsing to better utilize GOptionContext.  This
eliminates most of the manual parsing and global options are now shown
in the help output.

Here's a sample:

    $ ostree admin --help
    Usage:
      ostree admin [OPTION...] --print-current-dir|COMMAND

    Builtin "admin" Commands:
      cleanup
      config-diff
      deploy
      init-fs
      instutil
      os-init
      status
      switch
      undeploy
      upgrade

    Help Options:
      -h, --help         Show help options

    Application Options:
      --sysroot=PATH     Create a new OSTree sysroot at PATH
      -v, --verbose      Print debug information during command processing
      --version          Print version information and exit

https://bugzilla.gnome.org/show_bug.cgi?id=740295
This commit is contained in:
Matthew Barnes committed 2014-11-24 19:36:07 -05:00
1 parent 3a9127f103
commit 97558276e4
42 files changed
+555 -500

No files matched your search

+4 -3
View File
@@ -22,6 +22,7 @@
#include "config.h"
#include "ot-main.h"
#include "ot-builtins.h"
#include "ostree.h"
#include "otutil.h"
@@ -55,9 +56,10 @@ cat_one_file (GFile *f,
}
gboolean
ostree_builtin_cat (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
ostree_builtin_cat (int argc, char **argv, GCancellable *cancellable, GError **error)
{
GOptionContext *context;
gs_unref_object OstreeRepo *repo = NULL;
gboolean ret = FALSE;
int i;
const char *rev;
@@ -66,9 +68,8 @@ ostree_builtin_cat (int argc, char **argv, OstreeRepo *repo, GCancellable *cance
gs_unref_object GFile *f = NULL;
context = g_option_context_new ("COMMIT PATH... - Concatenate contents of files");
g_option_context_add_main_entries (context, options, NULL);
if (!g_option_context_parse (context, &argc, &argv, error))
if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
goto out;
if (argc <= 2)