mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-27 18:25:59 +02:00
App: Support --verbose
Add the --verbose global option, which is made available as the App.verbose property. Some functions still take a verbose parameter, but the type of these parameters is converted from bool to bool|None. The idea is that, if they are None, their verbosity falls back to the global default. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
525fa34387
commit
67a2931f5e
5 changed files with 28 additions and 11 deletions
|
|
@ -82,7 +82,9 @@ class Distro(abc.ABC):
|
|||
async def _reboot_required(self, verbose: bool) -> bool:
|
||||
pass
|
||||
|
||||
async def reboot_required(self, verbose: bool=False) -> bool:
|
||||
async def reboot_required(self, verbose: bool|None=None) -> bool:
|
||||
if verbose is None:
|
||||
verbose = self.ctx.verbose_default
|
||||
return await self._reboot_required(verbose=verbose)
|
||||
|
||||
# -- select
|
||||
|
|
|
|||
|
|
@ -16,15 +16,19 @@ class ExecContext(abc.ABC):
|
|||
self.__verbose_default = verbose_default
|
||||
assert verbose_default is not None
|
||||
|
||||
def _verbose(self, verbose: bool|None):
|
||||
def _verbose(self, verbose: bool|None) -> bool:
|
||||
if verbose is not None:
|
||||
return verbose
|
||||
return self.__verbose_default
|
||||
|
||||
@property
|
||||
def interactive(self):
|
||||
def interactive(self) -> bool:
|
||||
return self.__interactive
|
||||
|
||||
@property
|
||||
def verbose_default(self) -> bool:
|
||||
return self.__verbose_default
|
||||
|
||||
@abc.abstractmethod
|
||||
async def _run(self, *args, **kwargs) -> Result:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -31,14 +31,18 @@ def pretty_cmd(cmd: list[str], wd=None):
|
|||
ret += f' in {wd}'
|
||||
return ret
|
||||
|
||||
# See ec.Local.run() for what this function does
|
||||
async def run_cmd(*args, ec: ExecContext|None=None, **kwargs) -> tuple[str|bytes|None, str|bytes|None]:
|
||||
# See ExecContext.run() for what this function does
|
||||
async def run_cmd(*args, ec: ExecContext|None=None, verbose: bool|None=None, **kwargs) -> tuple[str|bytes|None, str|bytes|None]:
|
||||
if verbose is None:
|
||||
verbose = False if ec is None else ec.verbose_default
|
||||
if ec is None:
|
||||
from .ec.Local import Local
|
||||
ec = Local()
|
||||
return await ec.run(*args, **kwargs)
|
||||
ec = Local(verbose_default=verbose)
|
||||
return await ec.run(verbose=verbose, *args, **kwargs)
|
||||
|
||||
async def run_curl(args: list[str], parse_json: bool=True, wd=None, throw=None, verbose=False, cmd_input=None, ec: ExecContext|None=None) -> dict|str: # export
|
||||
async def run_curl(args: list[str], parse_json: bool=True, wd=None, throw=None, verbose=None, cmd_input=None, ec: ExecContext|None=None) -> dict|str: # export
|
||||
if verbose is None:
|
||||
verbose = False if ec is None else ec.verbose_default
|
||||
cmd = ['curl']
|
||||
if not verbose:
|
||||
cmd.append('-s')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue