Class: EzPaaS::CLI::Commands::Apps

Inherits:
ServerCommands show all
Defined in:
lib/ezpaas/cli/commands/apps.rb

Instance Method Summary collapse

Instance Method Details

#createObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ezpaas/cli/commands/apps.rb', line 47

def create
  app_name = options[:name]

  unless app_name
    prompt = TTY::Prompt.new

    default = loop do
      default = "#{RandomWord.adjs(not_longer_than: 10).next}-#{RandomWord.nouns(not_longer_than: 10).next}"
      break default unless default.include?('_')
    end

    app_name = prompt.ask('What would you like to call your new app?', required: true, default: default)
  end

  pastel = Pastel.new

  app = client.create_app(app_name)['app']
  app_name = pastel.blue(app['name'])

  puts
  puts "App #{app_name} created successfully!"
end

#destroyObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ezpaas/cli/commands/apps.rb', line 72

def destroy
  pastel = Pastel.new

  puts
  puts '🚨  🚨  🚨   ' + pastel.red('WARNING: Destroying an app is ') + pastel.red.bold.underline('not') + pastel.red(' reversible!') + '   🚨  🚨  🚨'
  puts

  app_name = options[:app]

  prompt = TTY::Prompt.new

  unless app_name
    apps = client.apps
    app_names = apps.map { |e| e['name'] }
    app_name = prompt.select('Which app would you like to destroy?', app_names)
  end

  if prompt.yes?('Are you sure?', default: false)
    client.destroy_app(app_name)
    puts
    puts "App #{app_name} destroyed successfully!"
  else
    puts
    puts pastel.blue('Phew!') + ' App deletion aborted.'
  end
end

#listObject



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

def list
  apps = client.apps

  pastel = Pastel.new
  not_deployed = pastel.red('(not deployed)')

  table = TTY::Table.new(header: ['Name', 'Slug', 'Scale', 'URL']) do |t|
    apps.each do |app|

      app_name = app['name']

      app_slug = app['slug']

      url_string = app_slug ? URI::join(options[:server], "proxy/#{app_name}/") : not_deployed

      slug_string = app_slug || not_deployed

      if scale = app['scale']
        scale_string = app['scale'].map{ |k, v| "#{k}=#{v}" }.join('\n')
      else
        scale_string = not_deployed
      end

      t << [app_name, slug_string, scale_string, url_string]
    end
  end

  puts
  puts table.render(:unicode, multiline: true)
end