module AppArchetype::CLI::Prompts
CLI
output presenters
Constants
- VAR_PROMPT_MESSAGE
Variable prompt question. Asked when evaluating template variables
@param [AppArchetype::Template::Variable] variable
@return [Proc]
Public Class Methods
Prompt for requesting user input.
A default can be provided in the event the user does not provide an answer.
Validator also performs type conversion by default it is a string
@param message [String] @param default [Object] @param validator [Object|Lambda]
@return [Object]
# File lib/app_archetype/cli/prompts.rb, line 56 def ask(message, validator: String, default: nil) resp = prompt.ask(message, validator) return default if !default.nil? && resp.to_s.empty? resp end
Prompt for boolean variable. This quizzes the user as to whether they want the variable set or not. The response is returned to the caller.
@param [AppArchetype::Template::Variable] variable
@return [Boolean]
# File lib/app_archetype/cli/prompts.rb, line 110 def boolean_variable_prompt(variable) yes?( VAR_PROMPT_MESSAGE.call(variable) ) end
Y/N prompt to ensure user is sure they wish to delete the selected template
@param [AppArchetype::Template::Manifest] manifest
@return [Boolean]
# File lib/app_archetype/cli/prompts.rb, line 70 def delete_template(manifest) yes?( "Are you sure you want to delete `#{manifest.name}`?" ) end
Prompt for integer. This quizzes the user for their choice and then attempts to convert it to an integer.
In the event a non integer value is entered, a RuntimeError is thrown.
@param [AppArchetype::Template::Variable] variable
@return [Integer]
# File lib/app_archetype/cli/prompts.rb, line 127 def integer_variable_prompt(variable) ask( VAR_PROMPT_MESSAGE.call(variable), default: variable.default, validator: Integer ) end
Prompt returns a TTY prompt object for asking the user questions.
@return [HighLine]
# File lib/app_archetype/cli/prompts.rb, line 28 def prompt HighLine.new end
Prompt for a string. Asks user for input and returns it.
@param [AppArchetype::Template::Variable] variable
@return [String]
# File lib/app_archetype/cli/prompts.rb, line 143 def string_variable_prompt(variable) ask( VAR_PROMPT_MESSAGE.call(variable), default: variable.default ) end
Returns a variable prompt based on the type of variable required. Once prompt has been executed, the response is returned to the caller.
When the value is set in the manifest, the set value is returned without a prompt.
For boolean and integer variables, the relevant prompt function is called.
By default the string variable prompt will be used.
@param [AppArchetype::Template::Variable] var
@return [Object]
# File lib/app_archetype/cli/prompts.rb, line 93 def variable_prompt_for(var) return var.value if var.value? return boolean_variable_prompt(var) if var.type == 'boolean' return integer_variable_prompt(var) if var.type == 'integer' string_variable_prompt(var) end
A yes/no prompt for asking the user a yes or no question.
@return [Boolean]
# File lib/app_archetype/cli/prompts.rb, line 37 def yes?(message) prompt.ask("#{message} [Y/n]", String) { |input| input.strip == 'Y' } end