From 110f4337f2bd12ecbfd91b222af1baad3a14788a Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Tue, 22 Dec 2015 17:03:11 +1300 Subject: 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 Signed-off-by: Richard Purdie --- scripts/lib/argparse_oe.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'scripts/lib/argparse_oe.py') 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 -- cgit v1.2.3-54-g00ecf