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()
|
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'
|
print(f'usage: {sys.argv[0]} [-h] [-v] [-p] [-2] [-d DIR] [-e ENCODING] [ - | INPUT [INPUT...] OUTPUT ]\n\n'
|
||||||
'options:\n'
|
'options:\n'
|
||||||
' -h, --help show this help message and exit\n'
|
' -h, --help show this help message and exit\n'
|
||||||
@ -120,15 +120,16 @@ def usage() -> None:
|
|||||||
'\n'
|
'\n'
|
||||||
' - use stdin for retrieving input and output file names (semi-colon-seperated)\n'
|
' - use stdin for retrieving input and output file names (semi-colon-seperated)\n'
|
||||||
' INPUT name of an html input file\n'
|
' INPUT name of an html input file\n'
|
||||||
' OUTPUT name of an pdf output file', file=sys.stderr)
|
' OUTPUT name of an pdf output file',
|
||||||
sys.exit(1)
|
file=sys.stderr if error else sys.stdout)
|
||||||
|
sys.exit(1 if error else 0)
|
||||||
|
|
||||||
|
|
||||||
def version() -> None:
|
def version() -> None:
|
||||||
print(f'WinziPrint: {__version__}\n'
|
print(f'WinziPrint: {__version__}\n'
|
||||||
f'WeasyPrint: {weasyprint.__version__}',
|
f'WeasyPrint: {weasyprint.__version__}\n'
|
||||||
file=sys.stderr)
|
f'pypdf: {pypdf.__version__}')
|
||||||
sys.exit(1)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def _get_arg(args: list[str], n1: str, n2: str = None, flag: bool = False) -> Union[None, str, bool]:
|
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:
|
if n in args:
|
||||||
i = args.index(n)
|
i = args.index(n)
|
||||||
if i + 1 >= len(args):
|
if i + 1 >= len(args):
|
||||||
usage()
|
usage(True)
|
||||||
v = args[i + 1]
|
v = args[i + 1]
|
||||||
args.pop(i)
|
args.pop(i)
|
||||||
args.pop(i)
|
args.pop(i)
|
||||||
@ -167,7 +168,7 @@ def main() -> None:
|
|||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
_wrapper_convert(line.strip().split(';'), encoding=encoding, padding=double_paged, progress=progress)
|
_wrapper_convert(line.strip().split(';'), encoding=encoding, padding=double_paged, progress=progress)
|
||||||
elif len(args) < 2:
|
elif len(args) < 2:
|
||||||
usage()
|
usage(True)
|
||||||
else:
|
else:
|
||||||
_wrapper_convert(args, encoding=encoding, padding=double_paged, progress=progress)
|
_wrapper_convert(args, encoding=encoding, padding=double_paged, progress=progress)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user