Class: CF::App::Apps

Inherits:
Base
  • Object
show all
Defined in:
lib/cf/cli/app/app.rb,
lib/cf/cli/app/apps.rb

Constant Summary collapse

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

Instance Method Summary collapse

Methods inherited from Base

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

Methods included from LoginRequirements

#precondition

Methods inherited from CLI

#add_exception_name_to_msg, #build_client, #check_logged_in, #check_target, client, #client, client=, #client_target, #color_enabled?, #debug?, #default_action, #ensure_config_dir, #err, #execute, #fail, #fail_unknown, #force?, #formatted_exception_output, #help, #help_header, #invalidate_client, #log_error, #log_error_and_dump_crashlog, #name_list, #normalize_targets_info, #one_of, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #save_token_if_it_changes, #set_target, #table, #target_info, #targets_info, #user_colors, #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

#appObject


11
12
13
14
15
16
17
18
19
# File 'lib/cf/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


75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cf/cli/app/apps.rb', line 75

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

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

  true
end

#appsObject


13
14
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
# File 'lib/cf/cli/app/apps.rb', line 13

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
# File 'lib/cf/cli/app/app.rb', line 21

def display_app(a)
  status = app_status(a)

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

  indented do
    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


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cf/cli/app/apps.rb', line 57

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