Skip to content

Commit

Permalink
Add flag to automatically accept default configuration values
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Oct 26, 2016
1 parent 0b28c00 commit 1e66495
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions esrally/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,19 @@ def __init__(self, i=input, sec_i=getpass.getpass, o=console.println):
self.i = i
self.sec_i = sec_i
self.o = o
self.assume_defaults = False

def create_config(self, config_file, advanced_config=False):
def create_config(self, config_file, advanced_config=False, assume_defaults=False):
"""
Either creates a new configuration file or overwrites an existing one. Will ask the user for input on configurable properties
and writes them to the configuration file in ~/.rally/rally.ini.
:param config_file:
:param advanced_config: Whether to ask for properties that are not necessary for everyday use (on a dev machine). Default: False.
:param assume_defaults: If True, assume the user accepted all values for which defaults are provided. Mainly intended for automatic
configuration in CI run. Default: False.
"""
self.assume_defaults = assume_defaults
if advanced_config:
self.o("Running advanced configuration. You can get additional help at:")
self.o("")
Expand Down Expand Up @@ -386,12 +391,16 @@ def _ask_env_name(self):
check_pattern=ConfigFactory.ENV_NAME_PATTERN)

def _ask_property(self, prompt, mandatory=True, check_path_exists=False, check_pattern=None, sensitive=False, default_value=None):
print("ASSUME DEFAULTS: %s" % (str(self.assume_defaults)))
if default_value is not None:
final_prompt = "%s [default: '%s']: " % (prompt, default_value)
else:
final_prompt = "%s: " % prompt
while True:
if sensitive:
if self.assume_defaults and default_value is not None:
self.o(final_prompt)
value = None
elif sensitive:
value = self.sec_i(final_prompt)
else:
value = self.i(final_prompt)
Expand Down
7 changes: 6 additions & 1 deletion esrally/rally.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ def positive_number(v):
help="show additional configuration options (default: false)",
default=False,
action="store_true")
p.add_argument(
"--assume-defaults",
help="Automatically accept all options with default values (default: false)",
default=False,
action="store_true")

for p in [parser, race_parser]:
p.add_argument(
Expand Down Expand Up @@ -396,7 +401,7 @@ def derive_sub_command(args, cfg):

def ensure_configuration_present(cfg, args, sub_command):
if sub_command == "configure":
config.ConfigFactory().create_config(cfg.config_file, advanced_config=args.advanced_config)
config.ConfigFactory().create_config(cfg.config_file, advanced_config=args.advanced_config, assume_defaults=args.assume_defaults)
exit(0)
else:
if cfg.config_present():
Expand Down

0 comments on commit 1e66495

Please sign in to comment.