Class: VMC::App::Apps

Inherits:
Base show all
Defined in:
lib/vmc/cli/app/app.rb,
lib/vmc/cli/app/apps.rb

Constant Summary collapse

IS_UTF8 =
!!(ENV["LC_ALL"] || ENV["LC_CTYPE"] || ENV["LANG"] || "")["UTF-8"].freeze

Constants inherited from Mothership

Mothership::VERSION

Instance Attribute Summary

Attributes inherited from Mothership

#input

Instance Method Summary collapse

Methods inherited from Base

#app_status, #human_mb, #human_size, #megabytes, #memory_choices, #state_color

Methods inherited from V2CheckCLI

#fail_on_v2, #precondition

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

Methods inherited from Mothership

add_input, after, alias_command, around, before, change_argument, commands, #default_action, desc, #execute, #exit_status, #filter, filter, global_option, group, #help, #initialize, input, #interact, interactions, #invoke, method_added, option, #run, start, #unknown_command, #with_filters

Constructor Details

This class inherits a constructor from Mothership

Instance Method Details

#appObject



11
12
13
14
15
16
17
18
19
# File 'lib/vmc/cli/app/app.rb', line 11

def app
  app = input[:app]

  if quiet?
    line app.name
  else
    display_app(app)
  end
end

#app_matches?(a, options) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/vmc/cli/app/apps.rb', line 79

def app_matches?(a, options)
  if name = options[:name]
    return false if a.name !~ /#{name}/
  end

  if runtime = options[:runtime]
    return false if a.runtime.name !~ /#{runtime}/
  end

  if framework = options[:framework]
    return false if a.framework.name !~ /#{framework}/
  end

  if url = options[:url]
    return false if a.urls.none? { |u| u =~ /#{url}/ }
  end

  true
end

#appsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vmc/cli/app/apps.rb', line 15

def apps
  if space = input[:space]
    begin
      space.summarize!
    rescue CFoundry::APIError
    end

    apps =
      with_progress("Getting applications in #{c(space.name, :name)}") do
        space.apps
      end
  else
    apps =
      with_progress("Getting applications") do
        client.apps(:depth => 2)
      end
  end

  line unless quiet?

  if apps.empty? and !quiet?
    line "No applications."
    return
  end

  apps.reject! do |a|
    !app_matches?(a, input)
  end

  apps = apps.sort_by(&:name)

  if input[:full]
    spaced(apps) do |a|
      invoke :app, :app => a
    end
  elsif quiet?
    apps.each do |a|
      line a.name
    end
  else
    display_apps_table(apps)
  end
end

#display_app(a) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vmc/cli/app/app.rb', line 21

def display_app(a)
  status = app_status(a)

  line "#{c(a.name, :name)}: #{status}"

  indented do
    line "platform: #{b(a.framework.name)} on #{b(a.runtime.name)}"

    start_line "usage: #{b(human_mb(a.memory))}"
    print " #{d(IS_UTF8 ? "\xc3\x97" : "x")} #{b(a.total_instances)}"
    print " instance#{a.total_instances == 1 ? "" : "s"}"

    line

    unless a.urls.empty?
      line "urls: #{a.urls.collect { |u| b(u) }.join(", ")}"
    end

    unless a.services.empty?
      line "services: #{a.services.collect { |s| b(s.name) }.join(", ")}"
    end
  end
end

#display_apps_table(apps) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/vmc/cli/app/apps.rb', line 59

def display_apps_table(apps)
  table(
    ["name", "status", "usage", v2? && "plan", "runtime", "url"],
    apps.collect { |a|
      [ c(a.name, :name),
        app_status(a),
        "#{a.total_instances} x #{human_mb(a.memory)}",
        v2? && (a.production ? "prod" : "dev"),
        a.runtime.name,
        if a.urls.empty?
          d("none")
        elsif a.urls.size == 1
          a.url
        else
          "#{a.url}, ..."
        end
      ]
    })
end