Commit e70e059a authored by ∞'s avatar 💻

Add support for immediate options

parent c6b79943
Pipeline #3440 passed with stages
in 33 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):
......
......@@ -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
......@@ -58,11 +60,13 @@ class Parser:
if arg.startswith('-'):
key, value = arg.lstrip('-').split('=')
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)
self.funckwargs[key] = value
......@@ -70,9 +74,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(arg)
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