summaryrefslogtreecommitdiffstats
path: root/scripts/lib/argparse_oe.py
Commit message (Collapse)AuthorAgeFilesLines
* argparse_oe: Add int_positive typeAníbal Limón2017-07-211-0/+7
| | | | | | | | | | Sometimes only expect positive values from cmdline so it's better to filter at parsing cmdline step instead of validate later. (From OE-Core rev: 3ef5b518febd047bf90a0955fa2b9fb78ba6dde5) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* scripts/lib/argparse_oe: also change 'positional arguments' to 'arguments'Christopher Larson2016-05-061-0/+1
| | | | | | | | | | This aligns with our existing 'optional arguments' to 'options' change, and seems more intuitive for users. (From OE-Core rev: 8a1cd471210e5fb77952f28172084bf6a4fb73e8) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* scripts/lib/argparse_oe: simplify options title changeChristopher Larson2016-05-061-4/+1
| | | | | | | | | | There's no need to iterate over the action groups here, as self._optionals and self._positionals are available. (From OE-Core rev: 408694f4320f3cb52a391e5b927fb8c8ba16c1d2) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* scripts/lib/argparse_oe: show subparser help for unrecognized argsChristopher Larson2016-05-061-6/+43
| | | | | | | | | | | | As an example, `recipetool create foo bar baz` shows `recipetool: error: unrecognized arguments: bar baz` and then displays the main help, not the help for the create command. Fix by saving the subparser name and using it in parse_args() to look up the subparser. (From OE-Core rev: 7fdaaedf4c63c8d019f03f84e22f9b838ef19aa6) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* scripts/lib/argparse_oe: show self.prog in the error messageChristopher Larson2016-05-061-2/+7
| | | | | | | | | | This aligns our subclassed error() with that in the original class, using _print_message and self.prog. Also add a docstring based on the original. (From OE-Core rev: cf0c5175136966eefde8c0d9aa0679e85779f713) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* scripts/lib/argparse_oe: tweak title above optionsPaul Eggleton2016-02-211-0/+4
| | | | | | | | | | | | | | Naming these as "optional arguments" is perhaps slightly confusing since some of the positional arguments might also be optional; in addition it's rare (though possible) for options to be mandatory - up until recently we had a recipetool option (-o) that was mandatory. It's not perfect, but change it to "options" so it's at least a bit more appropriate. (From OE-Core rev: 55e675de6191bf7eccd26df29189f2a6faa40a20) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* devtool: categorise and order subcommands in help outputPaul Eggleton2016-02-211-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | The listing of subcommands in the --help output for devtool was starting to get difficult to follow, with commands appearing in no particular order (due to some being in separate modules and the order of those modules being parsed). Logically grouping the subcommands as well as being able to exercise some control over the order of the subcommands and groups would help, if we do so without losing the dynamic nature of the list (i.e. that it comes from the plugins). Argparse provides no built-in way to handle this and really, really makes it a pain to add, but with some subclassing and hacking it's now possible, and can be extended by any plugin as desired. To put a subcommand into a group, all you need to do is specify a group= parameter in the call to subparsers.add_parser(). you can also specify an order= parameter to make the subcommand sort higher or lower in the list (higher order numbers appear first, so use negative numbers to force items to the end if that's what you want). To add a new group, use subparsers.add_subparser_group(), supplying the name, description and optionally an order number for the group itself (again, higher numbers appear first). (From OE-Core rev: e1b9d31e6ea3c254ecfe940fe795af44761e0e69) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* devtool: add: allow specifying URL as positional argumentPaul Eggleton2015-12-281-0/+16
| | | | | | | | | | | | Having to specify -f is a little bit ugly when a URI is distinctive enough to recognise amongst the other positional parameters, so take it as an optional positional parameter. -f/--fetch is still supported, but deprecated. (From OE-Core rev: aedfc5a5db1c4b2b80a36147c9a13b31764d91dd) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* scripts/lib/argparse_oe: handle intermixing of optional positional argumentsPaul Eggleton2015-12-281-0/+39
| | | | | | | | | | | | | | | | | | | Python's argparse module can't handle when several optional positional arguments (set with nargs='?') are intermixed with other options. If the positional arguments aren't optional then this isn't an issue; thus when changing positional arguments to optional (as we are doing with devtool) we need this workaround. This is a pretty horrible hack, but we don't want this flexibility of ordering to disappear simply because we made some arguments optional. Unfortunately the corresponding bug remains unresolved upstream even in Python 3, and argparse is not really designed to be subclassed so it doesn't make things like this easy. (From OE-Core rev: 98fd5de373e16fe5d69a3065f844efc8037385bc) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
* scripts: print usage in argparse-using scripts when a command-line error occursPaul Eggleton2015-12-281-0/+11
For scripts that use Python's standard argparse module to parse command-line arguments, create a subclass which will show the usage the usage information when a command-line parsing error occurs. The most common case would be when the script is run with no arguments; at least then the user immediately gets to see what arguments they might need to pass instead of just an error message. (From OE-Core rev: d62fe7c9bc2df6a4464440a3cae0539074bf99aa) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>