Class: Skytap::Commands::Root

Inherits:
Base
  • Object
show all
Defined in:
lib/skytap/commands/root.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #command_options, #error, #global_options, #invoker, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#api_token, #ask, #ask_param, #command_line_params, #composed_params, #expected_args, #expected_options, #file_params, #find_id, #initialize, #interactive_params, #invoke, make_from, #noninteractive_params, #programmatic?, #solicit_user_input?, #username

Methods included from Help

#description, #help!, #help?, included, #parameters, #synopsis, #version?

Constructor Details

This class inherits a constructor from Skytap::Commands::Base

Class Method Details



10
11
12
# File 'lib/skytap/commands/root.rb', line 10

def self.banner_prefix
  'skytap'
end

.command_nameObject



14
15
16
# File 'lib/skytap/commands/root.rb', line 14

def self.command_name
  nil
end

.go!(logger, args, global_options, command_options, programmatic_context = false, &invoker) ⇒ Object



6
7
8
# File 'lib/skytap/commands/root.rb', line 6

def self.go!(logger, args, global_options, command_options, programmatic_context=false, &invoker)
  new(logger, args, global_options, command_options, programmatic_context, &invoker).invoke
end

.populate_with(specification = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/skytap/commands/root.rb', line 18

def self.populate_with(specification={})
  self.subcommands = specification.sort.collect do |resource, spec|
    Base.make_from(resource, spec).tap do |klass|
      klass.parent = self
    end
  end
end

Instance Method Details

#help_with_initial_setup!Object



30
31
32
33
34
35
36
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
72
73
74
75
# File 'lib/skytap/commands/root.rb', line 30

def help_with_initial_setup!
  if SkytapRC.exists? || !solicit_user_input?
    help_without_initial_setup!
  else
    logger.puts <<-"EOF"
Do you want to store your API credentials in a text file for convenience?

If you answer yes, your username and API token will be stored in a .skytaprc
file in plain text. If you answer no, you must provide your username and API
token each time you invoke this tool.

    EOF
    if ask('Store username?', ActiveSupport::OrderedHash['y', true, 'n', false, :default, 'y'])
      username = ask('Skytap username:') while username.blank?
    end
    if ask('Store API token?', ActiveSupport::OrderedHash['y', true, 'n', false, :default, 'y'])
      logger.puts "\nYour API security token is on the My Account page.\nIf missing, ask your admin to enable API tokens on the Security Policies page."
      # Allow API token to be blank, in case the user realizes they don't have one.
      api_token = ask('API token:')
    end

    logger.puts <<-"EOF"

Do you want to turn on interactive mode?

If so, you will be shown the request parameters available for a command and
asked if you want to enter any. If you plan to use this tool primarily in
scripts, you may want to answer no.
    EOF

    ask_mode = ask('Enable interactive mode?', ActiveSupport::OrderedHash['y', true, 'n', false, :default, 'y'])

    config = global_options.symbolize_keys.merge(:username => username, :'api-token' => api_token, :ask => ask_mode)

    SkytapRC.write(config)

    logger.puts <<-"EOF"
Config file written to #{SkytapRC::RC_FILE}.

Example commands:
#{'skytap'.bright} - show all commands
#{'skytap help configuration'.bright} - show configuration commands
#{'skytap help vm upload'.bright} - help for VM upload command
    EOF
  end
end

#run!Object



26
27
28
# File 'lib/skytap/commands/root.rb', line 26

def run!
  help!
end