After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 740295 - Refactor command-line parsing
Refactor command-line parsing
Status: RESOLVED FIXED
Product: ostree
Classification: Infrastructure
Component: general
2014.4
Other Linux
: Normal normal
: ---
Assigned To: OSTree maintainer(s)
OSTree maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-11-18 03:17 UTC by Matthew Barnes
Modified: 2014-11-25 00:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (78.07 KB, patch)
2014-11-18 03:17 UTC, Matthew Barnes
reviewed Details | Review
Revised patch (80.75 KB, patch)
2014-11-24 20:59 UTC, Matthew Barnes
committed Details | Review

Description Matthew Barnes 2014-11-18 03:17:06 UTC
Created attachment 290890 [details] [review]
Proposed patch

This was just a weekend hack.

I refactored OSTree's command-line parsing to try and better utilize GOptionContext.  Primary goal was to show the global options in the help output (for the sake of newbies like me), but a nice side-effect is it eliminated most of the manual option parsing.

Still testing this, but it seems okay so far.

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
Comment 1 Colin Walters 2014-11-18 23:19:05 UTC
Review of attachment 290890 [details] [review]:

Wow, this looks pretty awesome.  I think I see how this works, we create an option context which knows about the subcommands.  The code does look nicer.

I tried applying this to master but hit some conflicts, can you rebase?
Comment 2 Matthew Barnes 2014-11-19 14:42:32 UTC
That's odd, I rechecked and my git repo was already up-to-date.  Are you maybe missing my manpage/option tweaks?  That's the latest commit on master as of this morning.

Basically the new "parse" functions have all the smarts.  They both list and handle the global options, and return back a new OstreeRepo or OstreeSysroot instance accordingly.
Comment 3 Matthew Barnes 2014-11-24 02:47:13 UTC
Caught that the GMainContext in ostree_usage() is leaking.  Fixed locally.
Comment 4 Matthew Barnes 2014-11-24 20:59:17 UTC
Created attachment 291417 [details] [review]
Revised patch

A bit more polish.
Comment 5 Colin Walters 2014-11-24 22:23:11 UTC
Review of attachment 291417 [details] [review]:

This looks good to me.
Comment 6 Matthew Barnes 2014-11-25 00:38:35 UTC
Thanks for the review!

https://git.gnome.org/browse/ostree/commit/?id=97558276e4f855442337be01abc8f90cf0dd1810