Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Improve help and cmdline option names for --generate-config options #5512

Merged
merged 3 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5512.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve help and cmdline option names for --generate-config options.
50 changes: 28 additions & 22 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,37 +254,43 @@ def load_or_generate_config(cls, description, argv):
help="Specify config file. Can be given multiple times and"
" may specify directories containing *.yaml files.",
)
config_parser.add_argument(

generate_group = config_parser.add_argument_group("Config generation")
generate_group.add_argument(
"--generate-config",
action="store_true",
help="Generate a config file for the server name",
help="Generate a config file, then exit.",
)
config_parser.add_argument(
generate_group.add_argument(
"--generate-missing-configs",
"--generate-keys",
action="store_true",
help="Generate any missing additional config files, then exit.",
)
generate_group.add_argument(
"-H", "--server-name", help="The server name to generate a config file for."
)
generate_group.add_argument(
"--report-stats",
action="store",
help="Whether the generated config reports anonymized usage statistics",
help="Whether the generated config reports anonymized usage statistics.",
choices=["yes", "no"],
)
config_parser.add_argument(
"--generate-keys",
action="store_true",
help="Generate any missing key files then exit",
)
config_parser.add_argument(
generate_group.add_argument(
"--config-directory",
"--keys-directory",
metavar="DIRECTORY",
help="Used with 'generate-*' options to specify where files such as"
" signing keys should be stored, unless explicitly"
" specified in the config.",
)
config_parser.add_argument(
"-H", "--server-name", help="The server name to generate a config file for"
help=(
"Specify where additional config files such as signing keys and log"
" config should be stored. Defaults to the same directory as the main"
" config file."
),
)
config_args, remaining_args = config_parser.parse_known_args(argv)

config_files = find_config_files(search_paths=config_args.config_path)

generate_keys = config_args.generate_keys
generate_missing_configs = config_args.generate_missing_configs

obj = cls()

Expand All @@ -303,8 +309,8 @@ def load_or_generate_config(cls, description, argv):
(config_path,) = config_files
if not cls.path_exists(config_path):
print("Generating config file %s" % (config_path,))
if config_args.keys_directory:
config_dir_path = config_args.keys_directory
if config_args.config_directory:
config_dir_path = config_args.config_directory
else:
config_dir_path = os.path.dirname(config_path)
config_dir_path = os.path.abspath(config_dir_path)
Expand Down Expand Up @@ -350,7 +356,7 @@ def load_or_generate_config(cls, description, argv):
)
% (config_path,)
)
generate_keys = True
generate_missing_configs = True

parser = argparse.ArgumentParser(
parents=[config_parser],
Expand All @@ -369,10 +375,10 @@ def load_or_generate_config(cls, description, argv):
)

config_dict = obj.read_config_files(
config_files, keys_directory=args.keys_directory
config_files, keys_directory=config_args.config_directory
)

if generate_keys:
if generate_missing_configs:
obj.generate_missing_files(config_dict)
return None

Expand Down