• 
      

    Switch to using argparse for argument parsing.

    Review Request #5617 — Created March 12, 2014 and submitted

    Information

    RBTools
    master
    2da8cda...

    Reviewers

    argparse is the successor to optparse, and has a lot of nice additions
    we may want to take advantage of. It knows how to do things like
    optional values to arguments flags, variable argument values, and
    "positional arguments" (such as a command name), reducing the amount of
    work we have to do.

    The two are pretty compatible, allowing for most of the porting effort
    to remain under the hood. New commands can certainly take advantage of
    the new support though.

    We still maintain our own Option and OptionGroup wrappers, which we
    still need in order to map to configuration keys.

    argparse is natively available on Python 2.7 or higher. For older
    versions, we depend on the 'argparse' package from PyPI, which provides
    compatibility with Python 2.7's argparse.

    Tested with both the native argparse in 2.7 and the downloaded version
    in 2.6 (fetched from running python2.6 setup.py develop).
    Note that argparse claims compatibility with 2.3 on, so we should be in good shape.

    Checked the help output for every command.

    Tested using all variations of --help (for both global help and per-command).

    Tested calling commands with flags and positional arguments after the command
    name.

    Tested calling commands with attempting to use flags before the command name,
    which correctly resulted in an error.

    Tested with custom scripts in the patch (using rbt-mycommand names). They got
    the correct arguments.

    Checked with the new guess support. Instead of needing to do the hacky argv
    manipulation from the first change, we can now nargs to say it optionally takes
    an argument, simplifying the code.

    david
    1. Ship It!

    2. 
        
    chipx86
    Review request changed
    Status:
    Completed