Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/cli.py
Show All 31 Lines | def parse_url(url): | ||||
"""CLI-specific helper to 'autocomplete' the provided url.""" | """CLI-specific helper to 'autocomplete' the provided url.""" | ||||
if not url.startswith("https://"): | if not url.startswith("https://"): | ||||
url = "https://" + url | url = "https://" + url | ||||
if not url.endswith("/"): | if not url.endswith("/"): | ||||
url += "/" | url += "/" | ||||
return url | return url | ||||
@swh_cli_group.group(name="scanner", context_settings=CONTEXT_SETTINGS) | CONFIG_FILE_HELP = f"""Configuration file: | ||||
The CLI option or the environment variable will fail if invalid. | |||||
CLI option is checked first. | |||||
Then, environment variable {CONFIG_ENVVAR} is checked. | |||||
Then, if cannot load the default path, a set of default values are used. | |||||
Default config path is {DEFAULT_CONFIG_PATH}. | |||||
Default config values are {DEFAULT_CONFIG}""" | |||||
SCANNER_HELP = f"""Software Heritage Scanner tools. | |||||
{CONFIG_FILE_HELP}""" | |||||
@swh_cli_group.group( | |||||
name="scanner", context_settings=CONTEXT_SETTINGS, help=SCANNER_HELP, | |||||
) | |||||
@click.option( | @click.option( | ||||
"-C", | "-C", | ||||
"--config-file", | "--config-file", | ||||
default=None, | default=None, | ||||
type=click.Path(exists=False, dir_okay=False, path_type=str), | type=click.Path(exists=False, dir_okay=False, path_type=str), | ||||
help=f"""YAML configuration file. If absent and cannot load the default one, | help="""YAML configuration file""", | ||||
zack: I guess you wanted this line to be CONFIG_FILE_HELP, and I don't get why CONFIG_FILE_HELP is… | |||||
tenmaAuthorUnsubmitted Done Inline ActionsIn fact, because of https://bugs.python.org/issue28739 and also because it is quite long text, I moved config details to the scanner help. It gives it more space and make it actually readable. Click does not let use format the text, it even removes single line breaks... tenma: In fact, because of https://bugs.python.org/issue28739 and also because it is quite long text… | |||||
tenmaAuthorUnsubmitted Done Inline Actions(sorry, last comment not complete) tenma: (sorry, last comment not complete)
Test it and see if you like it.
Also pay attention: there is… | |||||
default parameters are used. | |||||
Default config path is {DEFAULT_CONFIG_PATH}. | |||||
Default config values are {DEFAULT_CONFIG} | |||||
""", | |||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def scanner(ctx, config_file: Optional[str]): | def scanner(ctx, config_file: Optional[str]): | ||||
"""Software Heritage Scanner tools.""" | |||||
if config_file is None and config.config_exists(DEFAULT_CONFIG_PATH): | if config_file is None and config.config_exists(DEFAULT_CONFIG_PATH): | ||||
config_file = DEFAULT_CONFIG_PATH | config_file = DEFAULT_CONFIG_PATH | ||||
if config_file is None: | if config_file is None: | ||||
conf = DEFAULT_CONFIG | conf = DEFAULT_CONFIG | ||||
else: | else: | ||||
# read_raw_config do not fail on ENOENT | # read_raw_config do not fail on ENOENT | ||||
if not config.config_exists(config_file): | if not config.config_exists(config_file): | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |
I guess you wanted this line to be CONFIG_FILE_HELP, and I don't get why CONFIG_FILE_HELP is referencing itself. Am I missing something magic or are these typos?