From 5c38dc13b0384bbd690198385352b87b9d65f87a Mon Sep 17 00:00:00 2001 From: jpic Date: Sat, 15 Feb 2020 19:47:24 +0100 Subject: [PATCH] Add debug option back --- shlax/actions/base.py | 10 ++++++++++ shlax/cli.py | 4 ++++ shlax/output.py | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/shlax/actions/base.py b/shlax/actions/base.py index 4b90331..d27db4f 100644 --- a/shlax/actions/base.py +++ b/shlax/actions/base.py @@ -14,6 +14,16 @@ class Action: r'([^ =]+)=': '{blue}\\1{red}={reset} ', r'=': '{blue}={reset} ', } + options = dict( + debug=dict( + alias='d', + default='visit', + help=''' + Display debug output. Supports values (combinable): cmd,out,visit + '''.strip(), + immediate=True, + ), + ) def __init__(self, *args, **kwargs): self.args = args diff --git a/shlax/cli.py b/shlax/cli.py index 66708bf..fc43129 100644 --- a/shlax/cli.py +++ b/shlax/cli.py @@ -121,6 +121,10 @@ class ConsoleScript(cli2.ConsoleScript): self[name] = cli2.Callable( name, action.callable(), + options={ + k: cli2.Option(name=k, **v) + for k, v in action.options.items() + }, color=getattr(action, 'color', cli2.YELLOW), ) return super().__call__(*args, **kwargs) diff --git a/shlax/output.py b/shlax/output.py index 259a221..2ca97f0 100644 --- a/shlax/output.py +++ b/shlax/output.py @@ -53,7 +53,8 @@ class Output: ).encode('utf8')) if flush: - self.write(b'\n') + if not line.endswith('\n'): + self.write(b'\n') self.flush() def cmd(self, line):