Class: EyProCli
- Inherits:
-
Thor
- Object
- Thor
- EyProCli
- Defined in:
- lib/ey_pro_cli.rb
Class Attribute Summary collapse
-
.core_file ⇒ Object
Returns the value of attribute core_file.
Instance Method Summary collapse
- #accounts ⇒ Object
- #applications ⇒ Object
- #deploy ⇒ Object
- #environments ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #version ⇒ Object
Class Attribute Details
.core_file ⇒ Object
Returns the value of attribute core_file.
17 18 19 |
# File 'lib/ey_pro_cli.rb', line 17 def core_file @core_file end |
Instance Method Details
#accounts ⇒ Object
26 27 28 29 |
# File 'lib/ey_pro_cli.rb', line 26 def accounts table_data = TablePrint::Printer.new(current_accounts, [{id: {width: 36}}, :name]) puts table_data.table_print end |
#applications ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ey_pro_cli.rb', line 49 def applications applications = if [:account] core_account_for().applications.all else current_accounts.map(&:applications).flatten.sort_by(&:id) end table_data = TablePrint::Printer.new(applications, [{id: {width: 10}}, :name]) puts table_data.table_print end |
#deploy ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ey_pro_cli.rb', line 106 def deploy = self..dup # Thor has a weird bug in it that seems to occassionally wipe out the class options check_for_updates unless ["no-update-check"] operator, environment = core_operator_and_environment_for() if operator.is_a?(Ey::Core::Client::Account) abort "Found account \#{operator.name} but requested account \#{options[:account]}.\nUse the ID of the account instead of the name.\nThis can be retrieved by running \"ey-pro accounts\".\n EOF\n .red unless operator.name == options[:account] || operator.id == options[:account]\n end\n\n unless environment\n abort \"Unable to locate environment \#{options[:environment]} in \#{operator.name}\".red\n end\n\n unless options[:account]\n options = self.options.dup.merge(environment: environment)\n end\n\n app = core_application_for(options)\n\n deploy_options = {}\n deploy_options.merge!(ref: options[:ref]) if options[:ref]\n deploy_options.merge!(migrate_command: options[:migrate]) if options[:migrate]\n deploy_options.merge!(migrate_command: '') if options[\"no-migrate\"]\n request = environment.deploy(app, deploy_options)\n\n puts <<-EOF\nDeploy started to environment: \#{environment.name} with application: \#{app.name}\nRequest ID: \#{request.id}\n EOF\n if options[:stream]\n request.subscribe { |m| print m[\"message\"] if m.is_a?(Hash) }\n puts \"\" # fix console output from stream\n else\n request.wait_for { |r| r.ready? } # dont raise from ready!\n end\n\n if request.successful\n puts \"Deploy successful!\".green\n else\n abort <<-EOF\nDeploy failed!\nRequest output:\n\#{request.message}\n EOF\n .red\n end\nend\n" |
#environments ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ey_pro_cli.rb', line 34 def environments environments = if [:account] core_account_for().environments.all else current_accounts.map(&:environments).flatten.sort_by(&:id) end table_data = TablePrint::Printer.new(environments, [{id: {width: 10}}, :name]) puts table_data.table_print end |
#login ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ey_pro_cli.rb', line 62 def login 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:: abort "Invalid email or password".yellow end |
#logout ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/ey_pro_cli.rb', line 86 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 |
#version ⇒ Object
159 160 161 162 163 164 |
# File 'lib/ey_pro_cli.rb', line 159 def version puts "Ey PRO CLI Version: \#{EyProCliVersion::VERSION}\nCore client version: \#{Ey::Core::VERSION}\n EOF\nend\n" |