Class: Kontena::Cli::Master::CreateCommand
- Inherits:
-
Kontena::Command
- Object
- Clamp::Command
- Kontena::Command
- Kontena::Cli::Master::CreateCommand
- Includes:
- Common
- Defined in:
- lib/kontena/cli/master/create_command.rb
Instance Attribute Summary
Attributes inherited from Kontena::Command
#arguments, #exit_code, #result
Instance Method Summary collapse
- #execute ⇒ Object
- #master_create_subcommands(tree) ⇒ Object
- #subcommand_tree(command = nil) ⇒ Object
Methods included from Common
#access_token=, #add_master, #any_key_to_continue, #any_key_to_continue_with_timeout, #api_url, #api_url=, #caret, #clear_current_grid, #client, #cloud_auth?, #cloud_client, #config, #confirm, #confirm_command, #current_grid, #current_master_index, #debug?, #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_token, #reset_client, #reset_cloud_client, #running_quiet?, #running_silent?, #running_verbose?, #spin_if, #spinner, #sprint, #sputs, #stdin_input, #use_refresh_token, #vfakespinner, #vputs, #vspinner, #warning
Methods inherited from Kontena::Command
banner, callback_matcher, #help_requested?, inherited, #instance, load_subcommand, requires_current_account_token, requires_current_account_token?, requires_current_grid, requires_current_grid?, requires_current_master, requires_current_master?, requires_current_master_token, requires_current_master_token?, #run, #run_callbacks, #verify_current_account_token, #verify_current_grid, #verify_current_master, #verify_current_master_token
Instance Method Details
#execute ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/kontena/cli/master/create_command.rb', line 37 def execute require 'shellwords' tree = master_create_subcommands(subcommand_tree) if tree.empty? exit_with_error "Install platform plugins first, use: kontena plugin" end cmd_class = prompt.select("Choose target platform") do || tree.each do |cmd_class| plugin_name = cmd_class.to_s[/Plugin::(.+?)::/, 1] next unless plugin_name .choice plugin_name, cmd_class end end = ['--no-prompt', '--silent', '--help', '--version'] = [] cmd_class..each do |option| next if option.switches.any?{ |sw| .include?(sw) } if option.type == :flag answer = prompt.yes?(option.description) if answer << option.switches.first end else answer = prompt.ask("#{option.description}: ", required: option.required?, default: option.default_value) if answer << "#{option.switches.first} #{answer.shellescape}" end end end cmd = [cmd_class.to_s[/Plugin::(.+?)::/, 1].downcase, 'master', 'create'] + Kontena.run!(cmd) end |
#master_create_subcommands(tree) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kontena/cli/master/create_command.rb', line 25 def master_create_subcommands(tree) creators = [] tree.each do |k,cmd| if cmd.kind_of?(Hash) creators += master_create_subcommands(cmd) elsif cmd.respond_to?(:callback_matcher) && cmd.callback_matcher == [:master, :create] creators << cmd end end creators end |
#subcommand_tree(command = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kontena/cli/master/create_command.rb', line 7 def subcommand_tree(command = nil) command ||= Kontena::MainCommand real_command = command.respond_to?(:subcommand_class) ? command.subcommand_class : command tree = {} real_command.recognised_subcommands.each do |sub_command| sub_command.names.each do |command_name| if sub_command.subcommand_class.has_subcommands? tree[command_name] = subcommand_tree(sub_command) else tree[command_name] = sub_command.subcommand_class end end end tree end |