aptible-cli 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e6d976b32bef3e1b4b34c49be4d7bfc524aa908
4
- data.tar.gz: b53c2136b9de6bd7f09b87950bdf214f58adfffd
3
+ metadata.gz: 0a4dc9b3d5de431e99e8aef2e76fdf0a352c03f7
4
+ data.tar.gz: eaaba80a605eff86cdddb3bec822a57ae928d871
5
5
  SHA512:
6
- metadata.gz: a7300533f684f475ad4e981d9b9534758ec666c1a57c83a4e605da5fe06286f03877b589303a7027b854fcf6470d1b76ba8cb987f0c4bf1423171abfa2f117db
7
- data.tar.gz: 4b6a7f6c26295bdbacdf9093113e32431a9c9ef73bbec8f2017996a89d0955a0c405305dfeec6e418181b96f326cb68551be16ed24b2b68ef83d8c3c7f268488
6
+ metadata.gz: d86fdfec7a75ba6aa0234551c0b7c326ee6b408175ea41d7fb8e44c96f0f2db2ecd9346029f4ac36295f1e68d9690f9928a74efdba79c6f8e63d88a6905d5253
7
+ data.tar.gz: 7a115c06a8479359d96dade21f5467cdba4b50af226d828062b0b9a88722d46ef1772fc1e22c56f991e1d6e874bce0e0fb9105997d9a944d876c3fdd3df29852
@@ -10,56 +10,71 @@ module Aptible
10
10
 
11
11
  class HandleFromGitRemote
12
12
  PATTERN = %r{
13
- :((?<environment_handle>[0-9a-z\-_\.]+?)/)?(?<app_handle>[0-9a-z\-_\.]+)\.git
14
- \z
15
- }x
13
+ :((?<environment_handle>[0-9a-z\-_\.]+?)/)?
14
+ (?<app_handle>[0-9a-z\-_\.]+)\.git
15
+ \z
16
+ }x
16
17
 
17
18
  def self.parse(url)
18
- PATTERN.match(url)
19
+ PATTERN.match(url) || {}
19
20
  end
20
21
  end
21
22
 
22
- def ensure_app(options = {})
23
- remote = options[:remote] || ENV['APTIBLE_REMOTE']
24
- handle = options[:app]
25
- if handle
26
- environment = ensure_environment(options)
27
- else
28
- handles = handle_from_remote(remote) || ensure_default_handle
29
- handle = handles[:app_handle]
30
- env_handle = handles[:environment_handle] || options[:environment]
31
- environment = ensure_environment(environment: env_handle)
32
- end
33
-
34
- app = app_from_handle(handle, environment)
35
- return app if app
36
- fail Thor::Error, "Could not find app #{handle}"
23
+ def self.included(base)
24
+ base.extend ClassMethods
37
25
  end
38
26
 
39
- def app_from_handle(handle, environment)
40
- environment.apps.find do |a|
41
- a.handle == handle
27
+ module ClassMethods
28
+ def app_options
29
+ option :app
30
+ option :environment
31
+ option :remote, aliases: '-r'
42
32
  end
43
33
  end
44
34
 
45
- def ensure_default_handle
46
- return default_handle if default_handle
47
- fail Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
48
- Could not find app in current working directory, please specify
49
- with --app
50
- ERR
35
+ def ensure_app(options = {})
36
+ remote = options[:remote] || ENV['APTIBLE_REMOTE'] || 'aptible'
37
+ app_handle = options[:app] || handles_from_remote(remote)[:app_handle]
38
+ environment_handle = options[:environment] ||
39
+ handles_from_remote(remote)[:environment_handle]
40
+
41
+ unless app_handle
42
+ fail Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
43
+ Could not find app in current working directory, please specify
44
+ with --app
45
+ ERR
46
+ end
47
+
48
+ environment = environment_from_handle(environment_handle)
49
+ if environment_handle && !environment
50
+ fail Thor::Error, "Could not find environment #{environment_handle}"
51
+ end
52
+ apps = apps_from_handle(app_handle, environment)
53
+ case apps.count
54
+ when 1
55
+ return apps.first
56
+ when 0
57
+ fail Thor::Error, "Could not find app #{app_handle}"
58
+ else
59
+ fail Thor::Error, 'Multiple apps exist, please specify environment'
60
+ end
51
61
  end
52
62
 
53
- def default_handle
54
- handle_from_remote(:aptible)
63
+ def apps_from_handle(handle, environment)
64
+ if environment
65
+ apps = environment.apps
66
+ else
67
+ apps = Aptible::Api::App.all(token: fetch_token)
68
+ end
69
+ apps.select { |a| a.handle == handle }
55
70
  end
56
71
 
57
- def handle_from_remote(remote_name)
72
+ def handles_from_remote(remote_name)
58
73
  git = Git.open(Dir.pwd)
59
74
  aptible_remote = git.remote(remote_name).url || ''
60
75
  HandleFromGitRemote.parse(aptible_remote)
61
76
  rescue
62
- nil
77
+ {}
63
78
  end
64
79
  end
65
80
  end
@@ -30,6 +30,7 @@ module Aptible
30
30
  end
31
31
 
32
32
  def environment_from_handle(handle)
33
+ return nil unless handle
33
34
  Aptible::Api::Account.all(token: fetch_token).find do |a|
34
35
  a.handle == handle
35
36
  end
@@ -4,6 +4,7 @@ module Aptible
4
4
  module Apps
5
5
  def self.included(thor)
6
6
  thor.class_eval do
7
+ include Helpers::App
7
8
  include Helpers::Environment
8
9
  include Helpers::Token
9
10
 
@@ -33,8 +34,7 @@ module Aptible
33
34
  end
34
35
 
35
36
  desc 'apps:scale TYPE NUMBER', 'Scale app to NUMBER of instances'
36
- option :app
37
- option :environment
37
+ app_options
38
38
  define_method 'apps:scale' do |type, n|
39
39
  num = Integer(n)
40
40
  app = ensure_app(options)
@@ -43,9 +43,8 @@ module Aptible
43
43
  attach_to_operation_logs(op)
44
44
  end
45
45
 
46
- option :app
47
- option :environment
48
46
  desc 'apps:deprovision', 'Deprovision an app'
47
+ app_options
49
48
  define_method 'apps:deprovision' do
50
49
  app = ensure_app(options)
51
50
  say "Deprovisioning #{app.handle}..."
@@ -10,8 +10,7 @@ module Aptible
10
10
  include Helpers::App
11
11
 
12
12
  desc 'config', "Print an app's current configuration"
13
- option :app
14
- option :remote, aliases: '-r'
13
+ app_options
15
14
  def config
16
15
  app = ensure_app(options)
17
16
  config = app.current_configuration
@@ -20,8 +19,7 @@ module Aptible
20
19
  end
21
20
 
22
21
  desc 'config:add', 'Add an ENV variable to an app'
23
- option :app
24
- option :remote, aliases: '-r'
22
+ app_options
25
23
  define_method 'config:add' do |*args|
26
24
  # FIXME: define_method - ?! Seriously, WTF Thor.
27
25
  app = ensure_app(options)
@@ -32,15 +30,13 @@ module Aptible
32
30
  end
33
31
 
34
32
  desc 'config:set', 'Alias for config:add'
35
- option :app
36
- option :remote, aliases: '-r'
33
+ app_options
37
34
  define_method 'config:set' do |*args|
38
35
  send('config:add', *args)
39
36
  end
40
37
 
41
38
  desc 'config:rm', 'Remove an ENV variable from an app'
42
- option :app
43
- option :remote, aliases: '-r'
39
+ app_options
44
40
  define_method 'config:rm' do |*args|
45
41
  # FIXME: define_method - ?! Seriously, WTF Thor.
46
42
  app = ensure_app(options)
@@ -51,8 +47,7 @@ module Aptible
51
47
  end
52
48
 
53
49
  desc 'config:unset', 'Alias for config:rm'
54
- option :app
55
- option :remote, aliases: '-r'
50
+ app_options
56
51
  define_method 'config:unset' do |*args|
57
52
  send('config:add', *args)
58
53
  end
@@ -10,10 +10,8 @@ module Aptible
10
10
  include Helpers::App
11
11
 
12
12
  desc 'domains', "Print an app's current virtual domains"
13
- option :app
14
- option :environment
13
+ app_options
15
14
  option :verbose, aliases: '-v'
16
- option :remote, aliases: '-r'
17
15
  def domains
18
16
  app = ensure_app(options)
19
17
  print_vhosts(app) do |vhost|
@@ -10,8 +10,7 @@ module Aptible
10
10
  include Helpers::App
11
11
 
12
12
  desc 'logs', 'Follows logs from a running app'
13
- option :app
14
- option :remote, aliases: '-r'
13
+ app_options
15
14
  def logs
16
15
  app = ensure_app(options)
17
16
 
@@ -11,8 +11,7 @@ module Aptible
11
11
  include Helpers::Env
12
12
 
13
13
  desc 'ps', 'Display running processes for an app'
14
- option :app
15
- option :remote, aliases: '-r'
14
+ app_options
16
15
  def ps
17
16
  app = ensure_app(options)
18
17
 
@@ -8,8 +8,7 @@ module Aptible
8
8
  include Helpers::App
9
9
 
10
10
  desc 'rebuild', 'Rebuild an app, and restart its services'
11
- option :app
12
- option :remote, aliases: '-r'
11
+ app_options
13
12
  def rebuild
14
13
  app = ensure_app(options)
15
14
  operation = app.create_operation(type: 'rebuild')
@@ -8,8 +8,7 @@ module Aptible
8
8
  include Helpers::App
9
9
 
10
10
  desc 'restart', 'Restart all services associated with an app'
11
- option :app
12
- option :remote, aliases: '-r'
11
+ app_options
13
12
  def restart
14
13
  app = ensure_app(options)
15
14
  operation = app.create_operation(type: 'restart')
@@ -15,8 +15,7 @@ module Aptible
15
15
 
16
16
  If specifying an app, invoke via: aptible ssh [--app=APP] COMMAND
17
17
  LONGDESC
18
- option :app
19
- option :remote, aliases: '-r'
18
+ app_options
20
19
  option :force_tty, type: :boolean
21
20
  def ssh(*args)
22
21
  app = ensure_app(options)
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.6.0'
3
+ VERSION = '0.6.1'
4
4
  end
5
5
  end
@@ -35,8 +35,7 @@ describe Aptible::CLI::Agent do
35
35
  allow(service).to receive(:create_operation) { op }
36
36
  allow(subject).to receive(:options) { { app: 'hello' } }
37
37
  allow(op).to receive(:resource) { apps.first }
38
- allow(Aptible::Api::Account).to receive(:all) { [account] }
39
- allow(account).to receive(:apps) { apps }
38
+ allow(Aptible::Api::App).to receive(:all) { apps }
40
39
 
41
40
  subject.send('apps:scale', 'web', 3)
42
41
  end
@@ -35,8 +35,7 @@ describe Aptible::CLI::Agent do
35
35
  it 'should print out the hostnames' do
36
36
  allow(service).to receive(:create_operation) { op }
37
37
  allow(subject).to receive(:options) { { app: 'hello' } }
38
- allow(Aptible::Api::Account).to receive(:all) { [account] }
39
- allow(account).to receive(:apps) { apps }
38
+ allow(Aptible::Api::App).to receive(:all) { apps }
40
39
 
41
40
  expect(app).to receive(:vhosts) { [vhost1, vhost2] }
42
41
  expect(subject).to receive(:say).with('domain1')
@@ -68,8 +67,7 @@ describe Aptible::CLI::Agent do
68
67
  it 'should print hostnames if -v is passed' do
69
68
  allow(service).to receive(:create_operation) { op }
70
69
  allow(subject).to receive(:options) { { verbose: true, app: 'hello' } }
71
- allow(Aptible::Api::Account).to receive(:all) { [account] }
72
- allow(account).to receive(:apps) { apps }
70
+ allow(Aptible::Api::App).to receive(:all) { apps }
73
71
 
74
72
  expect(app).to receive(:vhosts) { [vhost1, vhost2] }
75
73
  expect(subject).to receive(:say).with('domain1 -> host1')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api