mirror of
https://git.yoctoproject.org/poky
synced 2026-06-07 15:09:50 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
ceaa4bfd09
commit
110f4337f2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user