Class: JDC::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, #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 JDC::Cli::Command::Base

Instance Method Details

#alias(k, v = nil) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/cli/commands/misc.rb', line 104

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

#aliasesObject



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

def aliases
  aliases = JDC::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



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

def frameworks
  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
# 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 ""
  display "Target:   #{target_url} (v#{info[:version]})"
  display "Client:   v#{JDC::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



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

def runtimes
  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 = JDC::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
    JDC::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 = JDC::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



112
113
114
115
116
117
118
119
120
121
# File 'lib/cli/commands/misc.rb', line 112

def unalias(key)
  aliases = JDC::Cli::Config.aliases
  if aliases.has_key?(key)
    aliases.delete(key)
    JDC::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 "jdc #{JDC::Cli::VERSION}"
end