Class: EyProCli

Inherits:
Thor
  • Object
show all
Defined in:
lib/ey_pro_cli.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.core_file ⇒ Object

Returns the value of attribute core_file.



15
16
17
# File 'lib/ey_pro_cli.rb', line 15

def core_file
  @core_file
end

Instance Method Details

#deploy ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ey_pro_cli.rb', line 68

def deploy
  check_for_updates unless options["no-update-check"]
  environment = core_environment_for(options)
  app = core_application_for(options)

  deploy_options = {}
  deploy_options.merge!(ref: options[:ref]) if options[:ref]
  deploy_options.merge!(migrate_command: options[:migrate]) if options[:migrate]
  deploy_options.merge!(migrate_command: '') if options["no-migrate"]
  request = environment.deploy(app, deploy_options)

  puts "Deploy started to environment: #{environment.name} with application: #{app.name}"
  if options[:stream]
    request.subscribe { |m| print m["message"] if m.is_a?(Hash) }
    puts "" # fix console output from stream
  else
    request.ready!
  end

  if request.successful
    puts "Deploy successful!"
  else
    abort "Deploy failed!"
  end
end

#login ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ey_pro_cli.rb', line 24

def 
  email    = ENV["EMAIL"]    || ask("Email:")
  password = ENV["PASSWORD"] || ask("Password:", echo: false)

  token = unauthenticated_core_client.get_api_token(email, password).body["api_token"]

  existing_token = core_yaml[core_url]
  write_token    = if existing_token && existing_token != token
                     puts "New token does not match existing token.  Overwriting".yellow
                     true
                   elsif existing_token == token
                     puts "Token already exists".green
                     false
                   else
                     puts "Writing token".green
                     true
                   end
  write_core_yaml(token) if write_token
rescue Ey::Core::Response::Unauthorized
  abort "Invalid email or password".yellow
end

#logout ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/ey_pro_cli.rb', line 48

def logout
  if core_yaml[core_url]
    core_yaml.delete(core_url)
    write_core_yaml
    puts "Successfully removed API token from credentials file".green
  else
    puts "No API token found".yellow
  end
end