Class: VMC::Cli::Command::Misc

Inherits:
Base show all
Defined in:
lib/cli/commands/misc.rb

Instance Attribute Summary

Attributes inherited from Base

#no_prompt, #prompt_ok

Instance Method Summary collapse

Methods inherited from Base

#auth_token, #client, #client_info, #frameworks_info, #initialize, #runtimes_info, #target_base, #target_url

Constructor Details

This class inherits a constructor from VMC::Cli::Command::Base

Instance Method Details

#alias(k, v = nil) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/cli/commands/misc.rb', line 107

def alias(k, v=nil)
  k,v = k.split('=') unless v
  aliases = VMC::Cli::Config.aliases
  aliases[k] = v
  VMC::Cli::Config.store_aliases(aliases)
  display "Successfully aliased '#{k}' to '#{v}'".green
end

#aliasesObject



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/cli/commands/misc.rb', line 95

def aliases
  aliases = VMC::Cli::Config.aliases
  return display JSON.pretty_generate(aliases) if @options[:json]
  return display "No Aliases" if aliases.empty?
  atable = table do |t|
    t.headings = 'Alias', 'Command'
    aliases.each { |k,v| t << [k, v] }
  end
  display "\n"
  display atable
end

#frameworksObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/cli/commands/misc.rb', line 83

def frameworks
  raise VMC::Client::AuthError unless client.logged_in?
  return display JSON.pretty_generate(frameworks_info) if @options[:json]
  return display "No Frameworks" if frameworks_info.empty?
  rtable = table do |t|
    t.headings = ['Name']
    frameworks_info.each { |f| t << f }
  end
  display "\n"
  display rtable
end

#infoObject



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
# File 'lib/cli/commands/misc.rb', line 45

def info
  info = client_info
  return display JSON.pretty_generate(info) if @options[:json]

  display "\n#{info[:description]}"
  display "For support visit #{info[:support]}"
  display ""
  display "Target:   #{target_url} (v#{info[:version]})"
  display "Client:   v#{VMC::Cli::VERSION}"
  if info[:user]
    display ''
    display "User:     #{info[:user]}"
  end
  if usage = info[:usage] and limits = info[:limits]
    tmem  = pretty_size(limits[:memory]*1024*1024)
    mem   = pretty_size(usage[:memory]*1024*1024)
    tser  = limits[:services]
    ser   = usage[:services]
    tapps = limits[:apps] || 0
    apps  = usage[:apps]  || 0
    display "Usage:    Memory   (#{mem} of #{tmem} total)"
    display "          Services (#{ser} of #{tser} total)"
    display "          Apps     (#{apps} of #{tapps} total)" if limits[:apps]
  end
end

#runtimesObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cli/commands/misc.rb', line 71

def runtimes
  raise VMC::Client::AuthError unless client.logged_in?
  return display JSON.pretty_generate(runtimes_info) if @options[:json]
  return display "No Runtimes" if runtimes_info.empty?
  rtable = table do |t|
    t.headings = 'Name', 'Description', 'Version'
    runtimes_info.each_value { |rt| t << [rt[:name], rt[:description], rt[:version]] }
  end
  display "\n"
  display rtable
end

#set_target(target_url) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cli/commands/misc.rb', line 27

def set_target(target_url)
  target_url = "http://#{target_url}" unless /^https?/ =~ target_url
  target_url = target_url.gsub(/\/+$/, '')
  client = VMC::Client.new(target_url)
  unless client.target_valid?
    if prompt_ok
      display "Host is not available or is not valid: '#{target_url}'".red
      show_response = ask "Would you like see the response?",
                          :default => false
      display "\n<<<\n#{client.raw_info}\n>>>\n" if show_response
    end
    exit(false)
  else
    VMC::Cli::Config.store_target(target_url)
    say "Successfully targeted to [#{target_url}]".green
  end
end

#targetObject



8
9
10
11
# File 'lib/cli/commands/misc.rb', line 8

def target
  return display JSON.pretty_generate({:target => target_url}) if @options[:json]
  banner "[#{target_url}]"
end

#targetsObject Also known as: tokens



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

def targets
  targets = VMC::Cli::Config.targets
  return display JSON.pretty_generate(targets) if @options[:json]
  return display 'None specified' if targets.empty?
  targets_table = table do |t|
    t.headings = 'Target', 'Authorization'
    targets.each { |target, token| t << [target, token] }
  end
  display "\n"
  display targets_table
end

#unalias(key) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/cli/commands/misc.rb', line 115

def unalias(key)
  aliases = VMC::Cli::Config.aliases
  if aliases.has_key?(key)
    aliases.delete(key)
    VMC::Cli::Config.store_aliases(aliases)
    display "Successfully unaliased '#{key}'".green
  else
    display "Unknown alias '#{key}'".red
  end
end

#versionObject



4
5
6
# File 'lib/cli/commands/misc.rb', line 4

def version
  say "vmc #{VMC::Cli::VERSION}"
end