aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lib/argparse_oe.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-12-22 17:03:11 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-22 16:44:03 +0000
commitaedfc5a5db1c4b2b80a36147c9a13b31764d91dd (patch)
tree548446ec57a61847b87fc527a61abbcd09f36117 /scripts/lib/argparse_oe.py
parent70ab08146e930f1fc55fdf5726a87303e20bd60f (diff)
downloadopenembedded-core-contrib-aedfc5a5db1c4b2b80a36147c9a13b31764d91dd.tar.gz
devtool: add: allow specifying URL as positional argument
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. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/argparse_oe.py')
-rw-r--r--scripts/lib/argparse_oe.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/scripts/lib/argparse_oe.py b/scripts/lib/argparse_oe.py
index ec7eb8d191..fd866922bd 100644
--- a/scripts/lib/argparse_oe.py
+++ b/scripts/lib/argparse_oe.py
@@ -1,6 +1,12 @@
import sys
import argparse
+class ArgumentUsageError(Exception):
+ """Exception class you can raise (and catch) in order to show the help"""
+ def __init__(self, message, subcommand=None):
+ self.message = message
+ self.subcommand = subcommand
+
class ArgumentParser(argparse.ArgumentParser):
"""Our own version of argparse's ArgumentParser"""
@@ -9,6 +15,16 @@ class ArgumentParser(argparse.ArgumentParser):
self.print_help()
sys.exit(2)
+ def error_subcommand(self, message, subcommand):
+ if subcommand:
+ for action in self._actions:
+ if isinstance(action, argparse._SubParsersAction):
+ for choice, subparser in action.choices.items():
+ if choice == subcommand:
+ subparser.error(message)
+ return
+ self.error(message)
+
def add_subparsers(self, *args, **kwargs):
ret = super(ArgumentParser, self).add_subparsers(*args, **kwargs)
ret._parser_class = ArgumentSubParser