Class: VMC::App::Base
- Inherits:
-
V2CheckCLI
- Object
- Mothership
- CLI
- V2CheckCLI
- VMC::App::Base
- Defined in:
- lib/vmc/cli/app/base.rb
Direct Known Subclasses
Apps, Crashes, Delete, Deprecated, Env, Files, Health, Instances, Logs, Push, Rename, Restart, Scale, Start, Stats, Stop
Instance Method Summary collapse
- #app_status(a) ⇒ Object
- #human_mb(num) ⇒ Object
- #human_size(num, precision = 1) ⇒ Object
- #megabytes(str) ⇒ Object
- #memory_choices(exclude = 0) ⇒ Object
-
#state_color(s) ⇒ Object
choose the right color for app/instance state.
Methods inherited from V2CheckCLI
Methods inherited from CLI
#check_logged_in, #check_target, #client, client, client=, #client_target, #color_enabled?, #debug?, #default_action, #ensure_config_dir, #err, #execute, #fail, #fail_unknown, #force?, #invalidate_client, #log_error, #name_list, #no_v2, #normalize_targets_info, #one_of, #precondition, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #save_token_if_it_changes, #set_target, #table, #target_file, #target_info, #targets_info, #tokens_file, #user_colors, #v2?, #verbose?, #wrap_errors
Methods included from Spacing
#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes
Methods included from Interactive
#ask, #handler, #input_state, #list_choices, #prompt, #show_default
Instance Method Details
#app_status(a) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/vmc/cli/app/base.rb', line 24 def app_status(a) health = a.health if a.debug_mode == "suspend" && health == "0%" c("suspended", :neutral) else c(health.downcase, state_color(health)) end end |
#human_mb(num) ⇒ Object
58 59 60 |
# File 'lib/vmc/cli/app/base.rb', line 58 def human_mb(num) human_size(num * 1024 * 1024, 0) end |
#human_size(num, precision = 1) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vmc/cli/app/base.rb', line 62 def human_size(num, precision = 1) sizes = %w(G M K) sizes.each.with_index do |suf, i| pow = sizes.size - i unit = 1024.0 ** pow if num >= unit return format("%.#{precision}f%s", num / unit, suf) end end format("%.#{precision}fB", num) end |
#megabytes(str) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vmc/cli/app/base.rb', line 75 def megabytes(str) if str =~ /T$/i str.to_i * 1024 * 1024 elsif str =~ /G$/i str.to_i * 1024 elsif str =~ /M$/i str.to_i elsif str =~ /K$/i str.to_i / 1024 else # assume megabytes str.to_i end end |
#memory_choices(exclude = 0) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vmc/cli/app/base.rb', line 34 def memory_choices(exclude = 0) info = client.info usage = info[:usage] limit = info[:limits][:memory] ceiling = if usage used = usage[:memory] limit - used + exclude else limit end mem = 64 choices = [] until mem > ceiling choices << human_mb(mem) mem *= 2 end choices end |
#state_color(s) ⇒ Object
choose the right color for app/instance state
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vmc/cli/app/base.rb', line 7 def state_color(s) case s when "STARTING" :neutral when "STARTED", "RUNNING" :good when "DOWN" :bad when "FLAPPING" :error when "N/A" :unknown else :warning end end |