Method: CommandKit::Interactive#ask_secret

Defined in:
lib/command_kit/interactive.rb

#ask_secret(prompt, required: true) ⇒ String

Asks the user for secret input.

Examples:

ask_secret("Password")
# Password: 
# => "s3cr3t"

Parameters:

  • prompt (String)

    The prompt that will be printed before reading input.

  • required (Boolean) (defaults to: true)

    Requires non-empty input.

Returns:

  • (String)

    The user input.



246
247
248
249
250
251
252
253
254
# File 'lib/command_kit/interactive.rb', line 246

def ask_secret(prompt, required: true)
  if stdin.respond_to?(:noecho)
    stdin.noecho do
      ask(prompt, required: required)
    end
  else
    ask(prompt, required: required)
  end
end