mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
Cmd / Cmds: Add config file support
An application based on Cmds will now try to read StringTree formatted config data from a file $HOME/.<name>rc, and make the data available via the newly added conf_value() method. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
b7de950750
commit
a4fb791649
2 changed files with 31 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ class Cmd(abc.ABC): # export
|
|||
self.parent = None
|
||||
self.children: List[Cmd] = []
|
||||
self.child_classes: List[Type[Cmd]] = []
|
||||
self.app: Optional[Cmds] = None
|
||||
|
||||
async def _run(self, args):
|
||||
pass
|
||||
|
|
@ -52,3 +53,9 @@ class Cmd(abc.ABC): # export
|
|||
# Will be called from App base class constructor and set up the parser hierarchy
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
pass
|
||||
|
||||
def conf_value(self, path, default=None):
|
||||
ret = None if self.app is None else self.app.conf_value(path, default)
|
||||
if ret is None and default is not None:
|
||||
return default
|
||||
return ret
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue