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

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

Constant Summary

Constants inherited from Base

Base::MANIFEST

Instance Attribute Summary

Attributes inherited from Base

#no_prompt, #prompt_ok

Instance Method Summary collapse

Methods inherited from Base

#auth_token, #client, #client_info, #default_infra, #find_in_hash, #find_symbol, #frameworks_info, #initialize, #load_manifest, #load_manifest_structure, #manifest, #manifest_file, #merge_manifest, #merge_parent, #resolve_in, #resolve_lexically, #resolve_manifest, #resolve_symbol, #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



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

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



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

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



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

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

#infrasObject



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

def infras
  infras_info = client.infras
  return display "Multiple infras not supported" if infras_info.empty?
  itable = table do |t|
    t.headings = [ 'Name','Description' ]
    infras_info.each { |i| t << [i[:infra], i[:description]] }
  end
  display "\n"
  display itable
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 = "https://#{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



126
127
128
129
130
131
132
133
134
135
# File 'lib/cli/commands/misc.rb', line 126

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 "as #{VMC::Cli::VERSION}"
end