diff --git a/changes/688.feature.rst b/changes/688.feature.rst new file mode 100644 index 00000000..4e995a2c --- /dev/null +++ b/changes/688.feature.rst @@ -0,0 +1,3 @@ +Improved password prompting in interactive mode so that there is now only a +single password prompt when no password is specified. +Previously, each interactive command prompted for the password in that case. diff --git a/zhmccli/zhmccli.py b/zhmccli/zhmccli.py index 9a60c51c..6b695b0f 100644 --- a/zhmccli/zhmccli.py +++ b/zhmccli/zhmccli.py @@ -326,10 +326,7 @@ def get_password_via_prompt(host, userid): """ if userid is not None and host is not None: ctx.obj.spinner.stop() - password = click.prompt( - "Enter password (for user {userid} at HMC {host})". - format(userid=userid, host=host), hide_input=True, - confirmation_prompt=False, type=str, err=True) + password = get_password(host, userid) ctx.obj.spinner.start() return password @@ -338,6 +335,11 @@ def get_password_via_prompt(host, userid): format(cmd=ctx.invoked_subcommand), error_format) + # Make sure that in interactive mode, we have the password (otherwise, + # every interactive command prompts for it). + if password is None and ctx.invoked_subcommand in (None, 'repl'): + password = get_password(host, userid) + # We create a command context for each command: An interactive command has # its own command context different from the command context for the # command line. @@ -350,6 +352,17 @@ def get_password_via_prompt(host, userid): ctx.invoke(repl) +def get_password(host, userid): + """ + Prompt for a password and return the password. + """ + password = click.prompt( + "Enter password (for user {userid} at HMC {host})". + format(userid=userid, host=host), hide_input=True, + confirmation_prompt=False, type=str, err=True) + return password + + def reset_logger(log_comp): """ Reset the logger for the specified log component to have exactly one