hrk 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c55c5d03bcb00380ffcff94955234658934ee118
4
- data.tar.gz: 72e2a53ee349c5dbaece355c70b89085dc72827f
3
+ metadata.gz: 9a5606eeb5d8dc713063b4d76ef4633a60d0ba61
4
+ data.tar.gz: db35ff5cc2c2ea9445087056d1057a4a1db4100f
5
5
  SHA512:
6
- metadata.gz: 4c5dfad9f5057ce40bda69d34dca06ccac6d068be94e607efabb66d29e08e7f838e72e5e58128e66d732b7e2ea31d52fda5f12e3dbb6f89cec7bb7e0626c4c1f
7
- data.tar.gz: 57f0447db88c4739215ed04c94f046e12db6da9983d2c048d34c3c0576c9c10076af74960824e4eb6d156d48688e87f46dd0a3f840f7aa62adcf0393859e1825
6
+ metadata.gz: 425ecb4c9bb064204f13a074b1e3b21b1c066a754241a5d62bfa66ff6a01d9b2bd69736aa85f778e5d9996f50f697ec4b9514ad56f4b5d9ed8a431b62cca0eb9
7
+ data.tar.gz: c3d7d9ae715a2a0ba7846c6915b975bbf6e589dafd06b0554ca9f2e604491447fc1c2f8531a54b79fc6b6a07be1af6a5b147b048f4405182c82416284d2aed78
data/README.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  Hrk 2 swim like a dolphin in a sea of heroku commands
4
4
 
5
+ ```
6
+ ,|
7
+ / ;
8
+ / \
9
+ : ,'(
10
+ |( `.\
11
+ : \ `\ \.
12
+ \ `. | `.
13
+ \ `-._ ; \
14
+ \ ``-.'.. _ `._
15
+ `. `-. ```-...__
16
+ .'`. --.. ``-..____
17
+ ,'.-'`,_-._ (((( <o. ,'
18
+ `' `-.)``-._-...__```` ____.-'
19
+ ,' _,'.--,---------'
20
+ _.-' _..-' ),'
21
+ ``--'' `
22
+ ```
23
+
5
24
  ## Getting started
6
25
 
7
26
  You can install the Hrk gem using the gem command:
@@ -21,7 +40,7 @@ $ bundle install
21
40
 
22
41
  And enjoy the hrk command awesome power:
23
42
  ```
24
- $ hrk your-heroku-remote-name: logs && hrk : run console
43
+ $ hrk logs -r your-heroku-remote-name && hrk run console
25
44
  ```
26
45
 
27
46
 
@@ -69,9 +88,9 @@ Yup. Now It doesn't look really that better now does it?
69
88
  Hrk remembers the previous remote you've used. So you can do:
70
89
 
71
90
  ```bash
72
- $ hrk this-relly-long-remote-name: run rake do:some:work && \
73
- hrk : run rake arrange:stuff && \
74
- hrk : run rake test:some:thingy
91
+ $ hrk -r this-relly-long-remote-name run rake do:some:work && \
92
+ hrk run rake arrange:stuff && \
93
+ hrk run rake test:some:thingy
75
94
  ```
76
95
 
77
96
  Isn't it more fun?
@@ -85,9 +104,9 @@ close your terminal.
85
104
 
86
105
  ```bash
87
106
  $ git push demo && \
88
- hrk demo: run rake set-this-once && \ # happens on demo
107
+ hrk -r demo run rake set-this-once && \ # happens on demo
89
108
  git push -f demo HEAD^ && \
90
- hrk : restart # also on demo
109
+ hrk restart # also on demo
91
110
  ```
92
111
 
93
112
  **...I chain hrk commands on concurrent terminals for different remotes?**
@@ -97,11 +116,11 @@ Then:
97
116
 
98
117
  ```bash
99
118
  # on terminal 1
100
- $ hrk demo: run rake db:migrate && \ # happens on demo
101
- hrk : restart # still on demo
119
+ $ hrk -r demo run rake db:migrate && \ # happens on demo
120
+ hrk restart # still on demo
102
121
  # on terminal 2
103
- $ hrk prod: run rake db:migrate && \ # happens on prod
104
- hrk : restart # still on prod
122
+ $ hrk -r prod run rake db:migrate && \ # happens on prod
123
+ hrk restart # still on prod
105
124
  ```
106
125
 
107
126
  **...I set another remote after completing a bunch of commands?**
@@ -109,11 +128,21 @@ $ hrk prod: run rake db:migrate && \ # happens on prod
109
128
  The last remote set is the one used by default for subsequent commands. So:
110
129
 
111
130
  ```bash
112
- $ hrk demo: run rake db:migrate && \ # happens on demo
113
- hrk : restart && \ # also on demo
114
- hrk prod: maintenance:on && \ # happens on prod
115
- hrk : run rake db:migrate && \ # also on prod
116
- hrk : maintenance:off # still on prod
131
+ $ hrk -r demo run rake db:migrate && \ # happens on demo
132
+ hrk restart && \ # also on demo
133
+ hrk -r prod maintenance:on && \ # happens on prod
134
+ hrk run rake db:migrate && \ # also on prod
135
+ hrk maintenance:off # still on prod
136
+ ```
137
+
138
+ **...I place the "-r remote" argument at the end of the command, the heroku way**
139
+
140
+ It just works.
141
+ ```bash
142
+ # this command
143
+ $ hrk run console -r demo
144
+ # is the same as
145
+ $ hrk -r demo run console
117
146
  ```
118
147
 
119
148
  ## Do I still need the heroku toolbelt?
@@ -1,25 +1,32 @@
1
1
  module Hrk
2
2
  module Execute
3
3
  class Command
4
- REMOTE_MATCHER = %r{\A(.+):\Z}
5
-
6
4
  attr_reader :env
7
5
 
8
6
  def initialize
9
7
  @env = Hrk::Env.new
10
8
  end
11
9
 
12
- def call remote, *args
13
- if remote == ':'
14
- raise ArgumentError.new("No remote has been previously defined") unless @env.remote?
15
- Hrk::Heroku.new(@env.remote).call(args.join(' '))
10
+ def call *args
11
+ remote = remote_name args
12
+ if remote
13
+ @env.remote = remote
14
+ Hrk::Heroku.new(remote).call(remoteless_command(remote, args))
16
15
  else
17
- raise ArgumentError.new("#{remote.inspect} isn't a proper remote marker") unless remote =~ REMOTE_MATCHER
18
- remote_name = remote[REMOTE_MATCHER, 1]
19
- @env.remote = remote_name
20
- Hrk::Heroku.new(remote_name).call(args.join(' '))
16
+ raise ArgumentError.new("No remote has been previously defined and the command does not explicitely mention a remote") unless @env.remote?
17
+ Hrk::Heroku.new(@env.remote).call(args.join(' '))
21
18
  end
22
19
  end
20
+
21
+ private
22
+
23
+ def remote_name args
24
+ args.each_cons(2).detect { |(parameter, _)| parameter == '-r' }.join ' ' rescue nil
25
+ end
26
+
27
+ def remoteless_command remote, args
28
+ args.join(' ').gsub(%r{\s*#{remote}\s*}, ' ').strip
29
+ end
23
30
  end
24
31
  end
25
32
  end
data/lib/hrk/heroku.rb CHANGED
@@ -1,18 +1,18 @@
1
1
  module Hrk
2
2
  class Heroku
3
- def initialize remote_name
4
- @remote_name = remote_name
3
+ def initialize remote
4
+ @remote = remote
5
5
  end
6
6
 
7
7
  def call command
8
8
  validate! command
9
- system %Q(heroku #{command} -r #{@remote_name})
9
+ system %Q(heroku #{command} #{@remote})
10
10
  end
11
11
 
12
12
  private
13
13
 
14
14
  def validate! command
15
- raise ExplicitApplicationError.new, "You're calling a command on remote #{@remote_name} yet the command explicitely references #{command[%r{-[ar]\s+\S+}]}" if command =~ %r{ -[ra]\b}
15
+ raise ExplicitApplicationError.new, "You're calling a command on remote #{@remote} yet the command explicitly references #{command[%r{-[ar]\s+\S+}]}" if command =~ %r{ -[ra]\b}
16
16
  end
17
17
 
18
18
  class ExplicitApplicationError < Exception
@@ -21,16 +21,16 @@ RSpec.describe Hrk::Execute::Command do
21
21
  describe "when the command returns #{result}" do
22
22
  before { allow(heroku).to receive(:call).and_return(result) }
23
23
 
24
- it { expect(command.call("#{remote}:", *args)).to eq result }
24
+ it { expect(command.call('-r', remote, *args)).to eq result }
25
25
  end
26
26
  end
27
27
 
28
28
  describe 'interactions' do
29
- before { command.call "#{remote}:", *args }
29
+ before { command.call '-r', remote, *args }
30
30
 
31
- it { expect(Hrk::Heroku).to have_received(:new).with(remote) }
31
+ it { expect(Hrk::Heroku).to have_received(:new).with("-r #{remote}") }
32
32
  it { expect(heroku).to have_received(:call).with("whatever that:may -b") }
33
- it { expect(command.env).to have_received(:remote=).with(remote) }
33
+ it { expect(command.env).to have_received(:remote=).with("-r #{remote}") }
34
34
  end
35
35
  end
36
36
 
@@ -41,14 +41,13 @@ RSpec.describe Hrk::Execute::Command do
41
41
  before { expect(command.env).not_to receive(:remote=) }
42
42
 
43
43
  it { expect { command.call }.to raise_error ArgumentError }
44
- it { expect { command.call "bad-remote", *other_args }.to raise_error ArgumentError }
45
- it { expect { command.call ":misplaced-marker", *other_args }.to raise_error ArgumentError }
46
- it { expect { command.call ":", *other_args }.to raise_error ArgumentError }
44
+ it { expect { command.call "parameterless-remote", *other_args }.to raise_error ArgumentError }
45
+ it { expect { command.call *other_args, '-r' }.to raise_error ArgumentError }
47
46
  end
48
47
  end
49
48
 
50
49
  context 'a remote was previously memorized' do
51
- let(:previous_remote) { "ye-olde-remote#{rand(1..9)}" }
50
+ let(:previous_remote) { "-r ye-olde-remote#{rand(1..9)}" }
52
51
  before { allow(command.env).to receive(:remote).and_return(previous_remote) }
53
52
  before { allow(command.env).to receive(:remote?).and_return(true) }
54
53
 
@@ -60,16 +59,16 @@ RSpec.describe Hrk::Execute::Command do
60
59
  describe "when the command returns #{result}" do
61
60
  before { allow(heroku).to receive(:call).and_return(result) }
62
61
 
63
- it { expect(command.call("#{remote}:", *args)).to eq result }
62
+ it { expect(command.call('-r', remote, *args)).to eq result }
64
63
  end
65
64
  end
66
65
 
67
66
  describe 'interactions' do
68
- before { command.call "#{remote}:", *args }
67
+ before { command.call '-r', remote, *args }
69
68
 
70
- it { expect(Hrk::Heroku).to have_received(:new).with(remote) }
69
+ it { expect(Hrk::Heroku).to have_received(:new).with("-r #{remote}") }
71
70
  it { expect(heroku).to have_received(:call).with("whatever that:may -b") }
72
- it { expect(command.env).to have_received(:remote=).with(remote) }
71
+ it { expect(command.env).to have_received(:remote=).with("-r #{remote}") }
73
72
  end
74
73
  end
75
74
 
@@ -80,28 +79,17 @@ RSpec.describe Hrk::Execute::Command do
80
79
  describe "when the command returns #{result}" do
81
80
  before { allow(heroku).to receive(:call).and_return(result) }
82
81
 
83
- it { expect(command.call(":", *args)).to eq result }
82
+ it { expect(command.call(*args)).to eq result }
84
83
  end
85
84
  end
86
85
 
87
86
  describe 'interactions' do
88
- before { command.call ":", *args }
87
+ before { command.call *args }
89
88
 
90
89
  it { expect(Hrk::Heroku).to have_received(:new).with(previous_remote) }
91
90
  it { expect(heroku).to have_received(:call).with("whatever that:may -b") }
92
91
  end
93
92
  end
94
-
95
- describe 'edge cases (no remote or improper remote)' do
96
- let(:other_args) { %W(something-#{rand(1..9)} or-another) }
97
-
98
- before { expect(heroku).not_to receive(:call) }
99
- before { expect(command.env).not_to receive(:remote=) }
100
-
101
- it { expect { command.call }.to raise_error ArgumentError }
102
- it { expect { command.call "bad-remote", *other_args }.to raise_error ArgumentError }
103
- it { expect { command.call ":misplaced-marker", *other_args }.to raise_error ArgumentError }
104
- end
105
93
  end
106
94
  end
107
95
  end
@@ -16,11 +16,11 @@ RSpec.describe Hrk::Heroku do
16
16
  before { allow(heroku).to receive(:system) }
17
17
 
18
18
  describe '(standard case)' do
19
- calling 'call rake db:rollback', on_remote: 'demo', starts: 'heroku call rake db:rollback -r demo'
20
- calling 'call rake db:migrate', on_remote: 'prod', starts: 'heroku call rake db:migrate -r prod'
21
- calling 'call console', on_remote: 'staging', starts: 'heroku call console -r staging'
22
- calling 'logs -t', on_remote: 'prod', starts: 'heroku logs -t -r prod'
23
- calling 'pgbackups:capture', on_remote: 'demo', starts: 'heroku pgbackups:capture -r demo'
19
+ calling 'call rake db:rollback', on_remote: '-r demo', starts: 'heroku call rake db:rollback -r demo'
20
+ calling 'call rake db:migrate', on_remote: '-r prod', starts: 'heroku call rake db:migrate -r prod'
21
+ calling 'call console', on_remote: '-r staging', starts: 'heroku call console -r staging'
22
+ calling 'logs -t', on_remote: '-r prod', starts: 'heroku logs -t -r prod'
23
+ calling 'pgbackups:capture', on_remote: '-r demo', starts: 'heroku pgbackups:capture -r demo'
24
24
  end
25
25
 
26
26
  describe '(edge case)' do
@@ -32,7 +32,7 @@ RSpec.describe Hrk::Heroku do
32
32
  end
33
33
 
34
34
  describe 'the result of the command' do
35
- subject(:heroku) { Hrk::Heroku.new('some-remote') }
35
+ subject(:heroku) { Hrk::Heroku.new('-r some-remote') }
36
36
  before { allow(heroku).to receive(:system).with('heroku some command -r some-remote').and_return(system_returns) }
37
37
 
38
38
  context 'the command result is truthy' do
metadata CHANGED
@@ -1,58 +1,79 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hrk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Belleville
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-04 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 3.1.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 4.0.0
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ">="
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 4.0.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: nyan-cat-formatter
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: '0.11'
40
+ - - "<"
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: '1.0'
34
43
  type: :development
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - ">="
47
+ - - '='
39
48
  - !ruby/object:Gem::Version
40
- version: '0'
49
+ version: '0.11'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: guard-rspec
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
- - - ">="
57
+ - - '='
58
+ - !ruby/object:Gem::Version
59
+ version: 4.5.0
60
+ - - "<"
46
61
  - !ruby/object:Gem::Version
47
- version: '0'
62
+ version: 5.0.0
48
63
  type: :development
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
52
- - - ">="
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 4.5.0
70
+ - - "<"
53
71
  - !ruby/object:Gem::Version
54
- version: '0'
55
- description: Hrk 2 swim like a dolphin in a sea of heroku commands
72
+ version: 5.0.0
73
+ description: |
74
+ Hrk gives you the hrk command that proxies commands to heroku, keeping track of
75
+ the latest remote you used so you don't have to keep on typing it on every
76
+ subsequent command.
56
77
  email: michel.belleville@gmail.com
57
78
  executables:
58
79
  - hrk
@@ -95,5 +116,5 @@ rubyforge_project:
95
116
  rubygems_version: 2.2.2
96
117
  signing_key:
97
118
  specification_version: 4
98
- summary: Hrk 2 swim like a dolphin in a sea of heroku commands
119
+ summary: Hrk remembers your heroku remotes
99
120
  test_files: []