Class: VMC::Cli::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Interactive
Defined in:
lib/cli/commands/base.rb

Direct Known Subclasses

Admin, Apps, Misc, Services, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
24
# File 'lib/cli/commands/base.rb', line 15

def initialize(options={})
  @options = options.dup
  @no_prompt = @options[:noprompts]
  @prompt_ok = !no_prompt

  # Suppress colorize on Windows systems for now.
  if WINDOWS
    VMC::Cli::Config.colorize = false
  end
end

Instance Attribute Details

#no_promptObject (readonly)

Returns the value of attribute no_prompt.



13
14
15
# File 'lib/cli/commands/base.rb', line 13

def no_prompt
  @no_prompt
end

#prompt_okObject (readonly)

Returns the value of attribute prompt_ok.



13
14
15
# File 'lib/cli/commands/base.rb', line 13

def prompt_ok
  @prompt_ok
end

Instance Method Details

#auth_tokenObject



48
49
50
# File 'lib/cli/commands/base.rb', line 48

def auth_token
  @auth_token ||= VMC::Cli::Config.auth_token
end

#client(cli = nil) ⇒ Object

Inject a client to help in testing.



27
28
29
30
31
32
33
34
# File 'lib/cli/commands/base.rb', line 27

def client(cli=nil)
  @client ||= cli
  return @client if @client
  @client = VMC::Client.new(target_url, auth_token)
  @client.trace = VMC::Cli::Config.trace if VMC::Cli::Config.trace
  @client.proxy_for @options[:proxy] if @options[:proxy]
  @client
end

#client_infoObject



36
37
38
# File 'lib/cli/commands/base.rb', line 36

def client_info
  @client_info ||= client.info
end

#frameworks_infoObject



65
66
67
68
69
70
71
72
73
# File 'lib/cli/commands/base.rb', line 65

def frameworks_info
  return @frameworks if @frameworks
  info = client_info
  @frameworks = []
  if info[:frameworks]
    info[:frameworks].each_value { |f| @frameworks << [f[:name]] }
  end
  @frameworks
end

#runtimes_infoObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cli/commands/base.rb', line 52

def runtimes_info
  return @runtimes if @runtimes
  info = client_info
  @runtimes = {}
  if info[:frameworks]
    info[:frameworks].each_value do |f|
      next unless f[:runtimes]
      f[:runtimes].each { |r| @runtimes[r[:name]] = r}
    end
  end
  @runtimes
end

#target_baseObject



44
45
46
# File 'lib/cli/commands/base.rb', line 44

def target_base
  @target_base ||= VMC::Cli::Config.suggest_url
end

#target_urlObject



40
41
42
# File 'lib/cli/commands/base.rb', line 40

def target_url
  @target_url ||= VMC::Cli::Config.target_url
end