Fix --help commandline argument (#7249)

I don't really remember why this was so complicated; I think it dates
back to the time when we had to instantiate the Config classes before
we could call `add_arguments` - ie before #5597. In any case, I don't
think there's a good reason for it any more, and the impact of it
being complicated is that `--help` doesn't work correctly.
This commit is contained in:
Richard van der Hoff 2020-04-09 12:44:37 +01:00 committed by GitHub
parent 7f7f9968b3
commit 5a709630bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 16 deletions

1
changelog.d/7249.bugfix Normal file
View File

@ -0,0 +1 @@
Fix --help command-line argument.

View File

@ -468,8 +468,8 @@ class RootConfig(object):
Returns: Config object, or None if --generate-config or --generate-keys was set Returns: Config object, or None if --generate-config or --generate-keys was set
""" """
config_parser = argparse.ArgumentParser(add_help=False) parser = argparse.ArgumentParser(description=description)
config_parser.add_argument( parser.add_argument(
"-c", "-c",
"--config-path", "--config-path",
action="append", action="append",
@ -478,7 +478,7 @@ class RootConfig(object):
" may specify directories containing *.yaml files.", " may specify directories containing *.yaml files.",
) )
generate_group = config_parser.add_argument_group("Config generation") generate_group = parser.add_argument_group("Config generation")
generate_group.add_argument( generate_group.add_argument(
"--generate-config", "--generate-config",
action="store_true", action="store_true",
@ -526,12 +526,13 @@ class RootConfig(object):
), ),
) )
config_args, remaining_args = config_parser.parse_known_args(argv) cls.invoke_all_static("add_arguments", parser)
config_args = parser.parse_args(argv)
config_files = find_config_files(search_paths=config_args.config_path) config_files = find_config_files(search_paths=config_args.config_path)
if not config_files: if not config_files:
config_parser.error( parser.error(
"Must supply a config file.\nA config file can be automatically" "Must supply a config file.\nA config file can be automatically"
' generated using "--generate-config -H SERVER_NAME' ' generated using "--generate-config -H SERVER_NAME'
' -c CONFIG-FILE"' ' -c CONFIG-FILE"'
@ -550,7 +551,7 @@ class RootConfig(object):
if config_args.generate_config: if config_args.generate_config:
if config_args.report_stats is None: if config_args.report_stats is None:
config_parser.error( parser.error(
"Please specify either --report-stats=yes or --report-stats=no\n\n" "Please specify either --report-stats=yes or --report-stats=no\n\n"
+ MISSING_REPORT_STATS_SPIEL + MISSING_REPORT_STATS_SPIEL
) )
@ -609,15 +610,6 @@ class RootConfig(object):
) )
generate_missing_configs = True generate_missing_configs = True
parser = argparse.ArgumentParser(
parents=[config_parser],
description=description,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
obj.invoke_all_static("add_arguments", parser)
args = parser.parse_args(remaining_args)
config_dict = read_config_files(config_files) config_dict = read_config_files(config_files)
if generate_missing_configs: if generate_missing_configs:
obj.generate_missing_files(config_dict, config_dir_path) obj.generate_missing_files(config_dict, config_dir_path)
@ -626,7 +618,7 @@ class RootConfig(object):
obj.parse_config_dict( obj.parse_config_dict(
config_dict, config_dir_path=config_dir_path, data_dir_path=data_dir_path config_dict, config_dir_path=config_dir_path, data_dir_path=data_dir_path
) )
obj.invoke_all("read_arguments", args) obj.invoke_all("read_arguments", config_args)
return obj return obj