restructure the output of --help
Using argument groups is a definite improvement over how things looked previously, but general group membership of individual items might be a thing to reconsider.
This commit is contained in:
@@ -32,7 +32,7 @@ class ParseAction(argparse.Action):
|
||||
"""Parse <key>=<value> options and set them as config values"""
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
try:
|
||||
key, value = values.split("=", 1)
|
||||
key, _, value = values.partition("=")
|
||||
try:
|
||||
value = json.loads(value)
|
||||
except ValueError:
|
||||
@@ -64,39 +64,131 @@ def build_parser():
|
||||
parser = argparse.ArgumentParser(
|
||||
usage="%(prog)s [OPTION]... URL...",
|
||||
formatter_class=Formatter,
|
||||
add_help=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-g", "--get-urls", dest="list_urls", action="count",
|
||||
help="Print URLs instead of downloading",
|
||||
|
||||
general = parser.add_argument_group("General Options")
|
||||
general.add_argument(
|
||||
"-h", "--help",
|
||||
action="help",
|
||||
help="Print this help message and exit"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-j", "--dump-json", dest="list_data", action="store_true",
|
||||
help="Print JSON information",
|
||||
general.add_argument(
|
||||
"--version",
|
||||
action="version", version=__version__,
|
||||
help="Print program version and exit",
|
||||
)
|
||||
parser.add_argument(
|
||||
general.add_argument(
|
||||
"-d", "--dest",
|
||||
metavar="DEST", action=ConfigAction, dest="base-directory",
|
||||
help="Destination directory",
|
||||
)
|
||||
parser.add_argument(
|
||||
general.add_argument(
|
||||
"-i", "--input-file",
|
||||
metavar="FILE", dest="inputfile",
|
||||
help="Download URLs found in FILE ('-' for stdin)",
|
||||
)
|
||||
general.add_argument(
|
||||
"--cookies",
|
||||
metavar="FILE", action=ConfigAction, dest="cookies",
|
||||
help="File to load additional cookies from",
|
||||
)
|
||||
general.add_argument(
|
||||
"--write-unsupported",
|
||||
metavar="FILE", dest="unsupportedfile",
|
||||
help=("Write URLs, which get emitted by other extractors but cannot "
|
||||
"be handled, to FILE"),
|
||||
)
|
||||
|
||||
output = parser.add_argument_group("Output Options")
|
||||
output.add_argument(
|
||||
"-q", "--quiet", dest="loglevel", action="store_const",
|
||||
const=logging.ERROR, default=logging.INFO,
|
||||
help="Activate quiet mode",
|
||||
)
|
||||
output.add_argument(
|
||||
"-v", "--verbose", dest="loglevel", action="store_const",
|
||||
const=logging.DEBUG, default=logging.INFO,
|
||||
help="Print various debugging information",
|
||||
)
|
||||
output.add_argument(
|
||||
"-g", "--get-urls", dest="list_urls", action="count",
|
||||
help="Print URLs instead of downloading",
|
||||
)
|
||||
output.add_argument(
|
||||
"-j", "--dump-json", dest="list_data", action="store_true",
|
||||
help="Print JSON information",
|
||||
)
|
||||
output.add_argument(
|
||||
"--list-modules", dest="list_modules", action="store_true",
|
||||
help="Print a list of available extractor modules",
|
||||
)
|
||||
output.add_argument(
|
||||
"--list-extractors", dest="list_extractors", action="store_true",
|
||||
help=("Print a list of extractor classes "
|
||||
"with description, (sub)category and example URL"),
|
||||
)
|
||||
output.add_argument(
|
||||
"--list-keywords", dest="list_keywords", action="store_true",
|
||||
help="Print a list of available keywords for the given URLs",
|
||||
)
|
||||
|
||||
downloader = parser.add_argument_group("Downloader Options")
|
||||
downloader.add_argument(
|
||||
"-R", "--retries",
|
||||
metavar="RETRIES", action=ConfigAction, dest="retries", type=int,
|
||||
help="Number of retries (default: 5)",
|
||||
)
|
||||
downloader.add_argument(
|
||||
"--http-timeout",
|
||||
metavar="SECONDS", action=ConfigAction, dest="timeout", type=float,
|
||||
help="Timeout for HTTP connections (defaut: no timeout)",
|
||||
)
|
||||
downloader.add_argument(
|
||||
"--abort-on-skip",
|
||||
action=ConfigConstAction, nargs=0, dest="skip", const="abort",
|
||||
help=("Abort extractor run if a file download would normally be "
|
||||
"skipped, i.e. if a file with the same filename already exists")
|
||||
)
|
||||
|
||||
configuration = parser.add_argument_group("Configuration Options")
|
||||
configuration.add_argument(
|
||||
"-c", "--config",
|
||||
metavar="CFG", dest="cfgfiles", action="append",
|
||||
help="Additional configuration files",
|
||||
)
|
||||
configuration.add_argument(
|
||||
"--config-yaml",
|
||||
metavar="CFG", dest="yamlfiles", action="append",
|
||||
help="Additional configuration files (YAML format)",
|
||||
)
|
||||
configuration.add_argument(
|
||||
"--ignore-config", dest="load_config", action="store_false",
|
||||
help="Do not read the default configuration files",
|
||||
)
|
||||
configuration.add_argument(
|
||||
"-o", "--option",
|
||||
metavar="OPT", action=ParseAction, dest="options", default=[],
|
||||
help="Additional '<key>=<value>' option values",
|
||||
)
|
||||
|
||||
authentication = parser.add_argument_group("Authentication Options")
|
||||
authentication.add_argument(
|
||||
"-u", "--username",
|
||||
metavar="USER", action=ConfigAction, dest="username",
|
||||
)
|
||||
parser.add_argument(
|
||||
authentication.add_argument(
|
||||
"-p", "--password",
|
||||
metavar="PASS", action=ConfigAction, dest="password",
|
||||
)
|
||||
parser.add_argument(
|
||||
authentication.add_argument(
|
||||
"--netrc",
|
||||
action=ConfigConstAction, nargs=0, dest="netrc", const=True,
|
||||
help="Use .netrc authentication data",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i", "--input-file",
|
||||
metavar="FILE", dest="inputfile",
|
||||
help="Download URLs found in local FILE ('-' for stdin)",
|
||||
)
|
||||
parser.add_argument(
|
||||
|
||||
selection = parser.add_argument_group("Selection Options")
|
||||
selection.add_argument(
|
||||
"--images",
|
||||
metavar="ITEM-SPEC", action=ConfigAction, dest="images",
|
||||
help=("Specify which images to download through a comma seperated list"
|
||||
@@ -104,86 +196,16 @@ def build_parser():
|
||||
"for example '--images -2,4,6-8,10-' will download images with "
|
||||
"index 1, 2, 4, 6, 7, 8 and 10 up to the last one")
|
||||
)
|
||||
parser.add_argument(
|
||||
selection.add_argument(
|
||||
"--chapters",
|
||||
metavar="ITEM-SPEC", action=ConfigAction, dest="chapters",
|
||||
help=("Same as '--images' except for chapters")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--abort-on-skip",
|
||||
action=ConfigConstAction, nargs=0, dest="skip", const="abort",
|
||||
help=("Abort extractor run if a file download would normally be "
|
||||
"skipped, i.e. if a file with the same filename already exists")
|
||||
)
|
||||
parser.add_argument(
|
||||
"-R", "--retries",
|
||||
metavar="RETRIES", action=ConfigAction, dest="retries", type=int,
|
||||
help="Number of retries (default: 5)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--http-timeout",
|
||||
metavar="SECONDS", action=ConfigAction, dest="timeout", type=float,
|
||||
help="Timeout for HTTP connections (defaut: no timeout)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cookies",
|
||||
metavar="FILE", action=ConfigAction, dest="cookies",
|
||||
help="File to load additional cookies from",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-c", "--config",
|
||||
metavar="CFG", dest="cfgfiles", action="append",
|
||||
help="Additional configuration files",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--config-yaml",
|
||||
metavar="CFG", dest="yamlfiles", action="append",
|
||||
help="Additional configuration files (YAML format)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--ignore-config", dest="load_config", action="store_false",
|
||||
help="Do not read the default configuration files",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o", "--option",
|
||||
metavar="OPT", action=ParseAction, dest="options", default=[],
|
||||
help="Additional '<key>=<value>' option values",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--write-unsupported", metavar="FILE", dest="unsupportedfile",
|
||||
help=("Write URLs, which get emitted by other extractors but cannot "
|
||||
"be handled, to FILE"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--list-extractors", dest="list_extractors", action="store_true",
|
||||
help=("Print a list of extractor classes "
|
||||
"with description, (sub)category and example URL"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--list-keywords", dest="list_keywords", action="store_true",
|
||||
help="Print a list of available keywords for the given URLs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--list-modules", dest="list_modules", action="store_true",
|
||||
help="Print a list of available modules/supported sites",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-q", "--quiet", dest="loglevel", action="store_const",
|
||||
const=logging.ERROR, default=logging.INFO,
|
||||
help="Activate quiet mode",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v", "--verbose", dest="loglevel", action="store_const",
|
||||
const=logging.DEBUG, default=logging.INFO,
|
||||
help="Print various debugging information",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--version", action="version", version=__version__,
|
||||
help="Print program version and exit"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"urls",
|
||||
nargs="*", metavar="URL",
|
||||
help="Url to download images from"
|
||||
help=argparse.SUPPRESS,
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
Reference in New Issue
Block a user