Class: Kontena::Cli::Stacks::YAML::Prompt
- Inherits:
-
Opto::Resolver
- Object
- Opto::Resolver
- Kontena::Cli::Stacks::YAML::Prompt
show all
- Includes:
- Common
- Defined in:
- lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb
Instance Method Summary
collapse
Methods included from Common
#access_token=, #add_master, #any_key_to_continue, #any_key_to_continue_with_timeout, #api_url, #api_url=, #api_url_version, #clear_current_grid, #client, #cloud_auth?, #cloud_client, #config, #confirm, #confirm_command, #current_account, #current_grid, #current_grid=, #current_master, #current_master=, #current_master_index, #display_account_login_info, #display_login_info, #display_logo, #display_master_login_info, #error, #exit_with_error, #kontena_account, #logger, #pastel, #print, #prompt, #puts, #require_api_url, #require_current_account, #require_current_grid, #require_current_master, #require_token, #reset_client, #reset_cloud_client, #running_silent?, #running_verbose?, #settings, #settings_filename, #spinner, #sprint, #sputs, #use_refresh_token, #vfakespinner, #vputs, #vspinner, #warning, #yes?
Instance Method Details
#ask ⇒ Object
58
59
60
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 58
def ask
prompt.ask(question_text, default: option.default)
end
|
#bool ⇒ Object
54
55
56
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 54
def bool
prompt.yes?(question_text, default: option.default == false ? false : true)
end
|
#boolean? ⇒ Boolean
17
18
19
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 17
def boolean?
option.type == 'boolean'
end
|
#enum ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 35
def enum
opts = option.handler.options[:options]
opts << { label: '(Other)', value: nil, description: '(Other)' } if enum_can_be_other?
answer = prompt.select(question_text) do ||
.enum ':' .default(opts.index {|opt| opt[:value] == option.default }.to_i + 1) if option.default
opts.each do |opt|
.choice opt[:label], opt[:value]
end
end
if answer.nil? && enum_can_be_other?
ask
else
answer
end
end
|
#enum? ⇒ Boolean
13
14
15
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 13
def enum?
option.type == 'enum'
end
|
#enum_can_be_other? ⇒ Boolean
31
32
33
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 31
def enum_can_be_other?
enum? && option.handler.options[:can_be_other] ? true : false
end
|
#prompt_word ⇒ Object
21
22
23
24
25
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 21
def prompt_word
return "Select" if enum?
return "Enable" if boolean?
"Enter"
end
|
#question_text ⇒ Object
27
28
29
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 27
def question_text
(!hint.nil? && hint != option.name) ? "#{hint} :" : "#{prompt_word} #{option.label || option.name} :"
end
|
#resolve ⇒ Object
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/kontena/cli/stacks/yaml/opto/prompt_resolver.rb', line 63
def resolve
return nil if option.skip?
if enum?
enum
elsif boolean?
bool
else
ask
end
end
|