winziprint: add error parameter for usage()
This commit is contained in:
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user