From: Christian Heller Date: Mon, 19 Aug 2024 04:02:17 +0000 (+0200) Subject: Improve usage help messaging. X-Git-Url: https://plomlompom.com/repos/te"st.html?a=commitdiff_plain;h=51b206d9f14788ee2a10e538e477fc5b04b6363a;p=stable_plom Improve usage help messaging. --- diff --git a/stable.py b/stable.py index d32f768..26bb8e4 100755 --- a/stable.py +++ b/stable.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 -from sys import exit as sys_exit +from sys import argv, exit as sys_exit from os.path import dirname, basename, splitext, join as path_join, exists from argparse import ArgumentParser from random import randint from stable.core import ImageMaker -DEFAULT_SCHEDULER='EulerAncestralDiscreteScheduler' +DEFAULT_SCHEDULER = 'EulerAncestralDiscreteScheduler' def save_path(count: int) -> str: @@ -20,11 +20,13 @@ def parse_args(): parser.add_argument('-o', '--output') parser.add_argument('-p', '--prompt') parser.add_argument('-H', '--help', action='help') - parser.add_argument('-S', '--list_schedulers', action='store_true') - parser.add_argument('-g', '--guidance', default=7.5, type=float, - help='default: 7.5') + parser.add_argument('-S', '--list-schedulers', action='store_true') parser.add_argument('-h', '--height', default=512, type=int, help='default: 512') + parser.add_argument('-w', '--width', default=512, type=int, + help='default: 512') + parser.add_argument('-g', '--guidance', default=7.5, type=float, + help='default: 7.5') parser.add_argument('-n', '--n_steps', default=15, type=int, help='default: 15') parser.add_argument('-q', '--quantity', default=1, type=int, @@ -32,15 +34,22 @@ def parse_args(): parser.add_argument('-r', '--randomness_seed', default=1, type=int, help='default: 1; if set 0, chosen randomnly') parser.add_argument('-s', '--scheduler', default=DEFAULT_SCHEDULER, - help=f'default: DEFAULT_SCHEDULER') - parser.add_argument('-w', '--width', default=512, type=int, - help='default: 512') + help=f'default: {DEFAULT_SCHEDULER}') parsed_args = parser.parse_args() if not parsed_args.list_schedulers: - if not parsed_args.output: - raise Exception('Unless -H or -S, need --output set.') - if not parsed_args.prompt: - raise Exception('Unless -H or -S, need --prompt set.') + prefix = f'{argv[0]}: error: unless calling with -H/--help or '\ + '-S/--list-schedulers, requiring ' + suffix = '' + if (not parsed_args.output) and (not parsed_args.prompt): + suffix = '-o/--output and -p/--prompt' + elif not parsed_args.output: + suffix = '-o/--output' + elif not parsed_args.prompt: + suffix = '-p/--prompt' + if (not parsed_args.output) or (not parsed_args.prompt): + parser.print_usage() + print(f'{prefix}{suffix}') + sys_exit(1) return parsed_args