Module: Dawn::CLI::OutputFormatter

Included in:
Helpers
Defined in:
lib/dawn/cli/output_formatter.rb

Instance Method Summary collapse

Instance Method Details

#format_apps(apps) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dawn/cli/output_formatter.rb', line 24

def format_apps(apps)
  table = Terminal::Table.new title: 'Apps',
                              headings: ['ID', 'Name', 'Formation'],
                              style: table_style
  apps.each do |app|
    form = app.formation.map { |k,v| "#{k}: #{v}" }.join("\n")
    table << [app.id, app.name, form]
    #table << :separator
  end

  table
end

#format_domains(domains) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dawn/cli/output_formatter.rb', line 37

def format_domains(domains)
  table = Terminal::Table.new title: 'Domains',
                              headings: ['ID', 'URL'],
                              style: table_style
  domains.each do |domain|
    table << [domain.id, domain.url]
    #table << :separator
  end

  table
end

#format_drains(drains) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dawn/cli/output_formatter.rb', line 49

def format_drains(drains)
  table = Terminal::Table.new title: 'Drains',
                              headings: ['ID', 'URL'],
                              style: table_style
  drains.each do |drain|
    table << [drain.id, drain.url]
    #table << :separator
  end

  table
end

#format_gears(gears) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dawn/cli/output_formatter.rb', line 61

def format_gears(gears)
  table = Terminal::Table.new title: 'Gears',
                              headings: ['ID', 'Name', 'Uptime'],
                              style: table_style
  gears.each do |gear|
    n = gear.uptime.to_i
    if n > 0
      scale  = TimeLord::Scale.new(n)
      uptime = "#{scale.to_value} #{scale.to_unit}"
    else
      uptime = "just now"
    end
    table << [gear.id, gear.name, uptime]
    #table << :separator
  end

  table
end

#format_keys(keys) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dawn/cli/output_formatter.rb', line 12

def format_keys(keys)
  table = Terminal::Table.new title: 'Keys',
                              headings: ['ID', 'Fingerprint', 'Key'],
                              style: table_style
  keys.each do |key|
    table << [key.id, key.fingerprint, key.key] #{}" ... "]#key.key[0, 20]] # truncate the key
    #table << :separator
  end

  table
end

#table_styleObject



8
9
10
# File 'lib/dawn/cli/output_formatter.rb', line 8

def table_style
  { } #width: 80 }
end