From 92c7a99cf8491460bbbdc34486847f1b2b47e2f1 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Mon, 23 Oct 2023 19:57:09 +0200 Subject: [PATCH] winziprint: add error parameter for usage() --- winziprint/winziprint.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/winziprint/winziprint.py b/winziprint/winziprint.py index 03edcea..c41fb12 100755 --- a/winziprint/winziprint.py +++ b/winziprint/winziprint.py @@ -108,7 +108,7 @@ def _wrapper_convert(args: list[str], encoding: str = None, padding: bool = Fals gc.collect() -def usage() -> None: +def usage(error: bool = False) -> None: print(f'usage: {sys.argv[0]} [-h] [-v] [-p] [-2] [-d DIR] [-e ENCODING] [ - | INPUT [INPUT...] OUTPUT ]\n\n' 'options:\n' ' -h, --help show this help message and exit\n' @@ -120,15 +120,16 @@ def usage() -> None: '\n' ' - use stdin for retrieving input and output file names (semi-colon-seperated)\n' ' INPUT name of an html input file\n' - ' OUTPUT name of an pdf output file', file=sys.stderr) - sys.exit(1) + ' OUTPUT name of an pdf output file', + file=sys.stderr if error else sys.stdout) + sys.exit(1 if error else 0) def version() -> None: print(f'WinziPrint: {__version__}\n' - f'WeasyPrint: {weasyprint.__version__}', - file=sys.stderr) - sys.exit(1) + f'WeasyPrint: {weasyprint.__version__}\n' + f'pypdf: {pypdf.__version__}') + sys.exit(0) def _get_arg(args: list[str], n1: str, n2: str = None, flag: bool = False) -> Union[None, str, bool]: @@ -142,7 +143,7 @@ def _get_arg(args: list[str], n1: str, n2: str = None, flag: bool = False) -> Un if n in args: i = args.index(n) if i + 1 >= len(args): - usage() + usage(True) v = args[i + 1] args.pop(i) args.pop(i) @@ -167,7 +168,7 @@ def main() -> None: for line in sys.stdin: _wrapper_convert(line.strip().split(';'), encoding=encoding, padding=double_paged, progress=progress) elif len(args) < 2: - usage() + usage(True) else: _wrapper_convert(args, encoding=encoding, padding=double_paged, progress=progress)