Commit 09287389 authored by John Kirkwood's avatar John Kirkwood

Merge branch 'master' into '4-cast-arguments-to-int-float-None'

parents aa7c11d3 8face8df
Pipeline #3594 passed with stages
in 40 seconds
......@@ -13,11 +13,13 @@ def command(**config):
class Option:
def __init__(self, name, help=None, color=None, alias=None):
def __init__(self, name, help=None, color=None, alias=None,
immediate=False):
self.name = name
self.help = help or 'Undocumented option'
self.color = color or ''
self.alias = alias
self.immediate = immediate
def option(name, **cfg):
......
......@@ -103,6 +103,11 @@ class Group(Callable, BaseGroup):
if doc:
self.doc = doc
@classmethod
def factory(cls, name, module_name):
doc = Importable.factory(module_name).doc
return cls(name, doc).add_module(module_name)
class ConsoleScript(BaseGroup):
def __init__(self, doc=None, argv=None, default_command='help'):
......
......@@ -17,6 +17,8 @@ class Parser:
self.extraargs = []
self.options = {}
self.immediate = True
def parse(self):
from .introspection import Callable
from .console_script import BaseGroup
......@@ -72,11 +74,13 @@ class Parser:
key, value = arg.lstrip('-').split('=')
value = self.cast_val(value)
option = self.get_option(key)
if option:
if option and (not option.immediate or self.immediate):
self.options[option.name] = value
else:
self.immediate = False
self.dashkwargs[key] = value
else:
self.immediate = False
key, value = arg.split('=', 1)
value = self.cast_val(value)
self.funckwargs[key] = value
......@@ -85,9 +89,11 @@ class Parser:
if arg.startswith('-'):
stripped = arg.lstrip('-')
option = self.get_option(stripped)
if option:
if option and (not option.immediate or self.immediate):
self.options[option.name] = True
else:
self.immediate = False
self.dashargs.append(stripped)
elif not filled:
self.immediate = False
self.funcargs.append(self.cast_val(arg))
......@@ -30,7 +30,7 @@ def autotest(path, cmd, ignore=None):
name = cmd.split(' ')[0]
ep = entrypoint_get(name)
if not ep:
raise Exception('Could not find entrypoint {name}')
raise Exception(f'Could not find entrypoint {name}')
console_script = ep.load()
console_script.argv = shlex.split(cmd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment