summaryrefslogtreecommitdiffstats
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-28 09:25:14 +0000
commit110f4337f2bd12ecbfd91b222af1baad3a14788a (patch)
treee98740bea214a85629e615ee27dadf2fe0eedc00 /scripts/lib/argparse_oe.py
parentceaa4bfd0942c2f68930a9a82d3bff3a9c2db32b (diff)
downloadpoky-110f4337f2bd12ecbfd91b222af1baad3a14788a.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. (From OE-Core rev: aedfc5a5db1c4b2b80a36147c9a13b31764d91dd) 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 @@
1import sys 1import sys
2import argparse 2import argparse
3 3
4class ArgumentUsageError(Exception):
5 """Exception class you can raise (and catch) in order to show the help"""
6 def __init__(self, message, subcommand=None):
7 self.message = message
8 self.subcommand = subcommand
9
4class ArgumentParser(argparse.ArgumentParser): 10class ArgumentParser(argparse.ArgumentParser):
5 """Our own version of argparse's ArgumentParser""" 11 """Our own version of argparse's ArgumentParser"""
6 12
@@ -9,6 +15,16 @@ class ArgumentParser(argparse.ArgumentParser):
9 self.print_help() 15 self.print_help()
10 sys.exit(2) 16 sys.exit(2)
11 17
18 def error_subcommand(self, message, subcommand):
19 if subcommand:
20 for action in self._actions:
21 if isinstance(action, argparse._SubParsersAction):
22 for choice, subparser in action.choices.items():
23 if choice == subcommand:
24 subparser.error(message)
25 return
26 self.error(message)
27
12 def add_subparsers(self, *args, **kwargs): 28 def add_subparsers(self, *args, **kwargs):
13 ret = super(ArgumentParser, self).add_subparsers(*args, **kwargs) 29 ret = super(ArgumentParser, self).add_subparsers(*args, **kwargs)
14 ret._parser_class = ArgumentSubParser 30 ret._parser_class = ArgumentSubParser