You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
826 B

from panflute import Doc
class Context:
def __init__(self, doc: Doc=None, parent: 'Context'=None):
self.parent = parent
self._commands = {}
self._flags = {}
self.doc = doc
def get_command(self, command: str):
if command in self._commands:
return self._commands[command]
elif self.parent:
return self.parent.get_command(command)
else:
return None
def set_command(self, command: str, val):
self._commands[command] = val
def unset_command(self, command: str):
del self._commands[command]
def is_flag_set(self, flag: str):
if flag in self._flags and self._flags[flag]:
return True
elif self.parent:
return self.parent.is_set(flag)
else:
return False
def set_flag(self, flag: str, val: bool):
self._flags[flag] = val
def unset_flag(self, flag):
del self._flags[flag]