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
Class Attribute Details
.core_file ⇒ Object
Returns the value of attribute core_file.
16 17 18 |
# File 'lib/ey_pro_cli.rb', line 16 def core_file @core_file end |
Instance Method Details
#accounts ⇒ Object
25 26 27 28 |
# File 'lib/ey_pro_cli.rb', line 25 def accounts table_data = TablePrint::Printer.new(current_accounts, [{id: {width: 36}}, :name]) puts table_data.table_print end |
#applications ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ey_pro_cli.rb', line 48 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
105 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 |
# File 'lib/ey_pro_cli.rb', line 105 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 \"Deploy started to environment: \#{environment.name} with application: \#{app.name}\"\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.ready!\n end\n\n if request.successful\n puts \"Deploy successful!\"\n else\n abort \"Deploy failed!\"\n end\nend\n" |
#environments ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ey_pro_cli.rb', line 33 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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ey_pro_cli.rb', line 61 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
85 86 87 88 89 90 91 92 93 |
# File 'lib/ey_pro_cli.rb', line 85 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 |