mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
Config.branch(): Add throw argument
In case a branch doesn't exist, branch() throws an error. Allow to return None instead. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
89578b788f
commit
e4cee86482
1 changed files with 5 additions and 2 deletions
|
|
@ -141,13 +141,16 @@ class Config(): # export
|
|||
def value(self, key: str, default = None) -> Optional[str]:
|
||||
return self.get(key, default)
|
||||
|
||||
def branch(self, path: str): # type: ignore # Optional[Config]: FIXME: Don't know how to get hold of this type here
|
||||
def branch(self, path: str, throw: bool=True): # type: ignore # Optional[Config]: FIXME: Don't know how to get hold of this type here
|
||||
if self.__conf:
|
||||
tree = self.__conf.get(path)
|
||||
if tree is None:
|
||||
msg = f'Tried to get non-existent branch "{path}" from config'
|
||||
if not throw:
|
||||
slog(DEBUG, msg)
|
||||
return None
|
||||
self.dump(ERR, msg)
|
||||
throw(msg)
|
||||
raise Exception(msg)
|
||||
return Config(tree=tree, parent=self) # type: ignore
|
||||
return None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue