mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 17:23:36 +02:00
lib.App: Add property cmdline
Add the property App.cmdline, containing the invoking command line as a string. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
f3c4a51b85
commit
6df4c86fc5
1 changed files with 9 additions and 0 deletions
|
|
@ -52,6 +52,7 @@ class App: # export
|
|||
from .Cmd import Cmd
|
||||
|
||||
self.__args: Namespace|None = None
|
||||
self.__cmdline: str|None = None
|
||||
self.__default_log_flags: str = os.getenv('JW_DEFAULT_LOG_FLAGS', default='stderr,position,prio,color')
|
||||
self.__default_log_level: str|int|None = os.getenv('JW_DEFAULT_LOG_LEVEL', default=NOTICE)
|
||||
self.__default_log_file: str|None = os.getenv('JW_DEFAULT_LOG_FILE', default=None)
|
||||
|
|
@ -137,6 +138,14 @@ class App: # export
|
|||
async def _run(self, args: argparse.Namespace) -> None:
|
||||
return await self.args.func(args)
|
||||
|
||||
@property
|
||||
def cmdline(self) -> str:
|
||||
if self.__cmdline is None:
|
||||
with open('/proc/self/cmdline', 'rb') as f:
|
||||
raw = f.read().split(b'\0')[:-1]
|
||||
self.__cmdline = ' '.join(shlex.quote(arg.decode()) for arg in raw)
|
||||
return self.__cmdline
|
||||
|
||||
@property
|
||||
def args(self) -> argparse.Namespace:
|
||||
return self.__args
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue