hrk 0.0.3 → 0.0.4
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 +4 -4
- data/lib/hrk/env.rb +34 -0
- data/lib/hrk/execute/command.rb +15 -2
- data/lib/hrk.rb +1 -0
- data/spec/hrk/execute/command_spec.rb +93 -15
- data/spec/hrk/execute_spec.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 172ab5ee4bd7bf4c32959c037180e9d0cba6b1ff
|
4
|
+
data.tar.gz: 7d03ead725cf5599a4262cc6b7a9cc095ee0bff8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 307c5ffa6b227953e064367f35ec37b25ebc46e0e18b4abb99b358b1839bbb975d9218292691a3dde17bce86ebbf3272022fa5ad456696cfc9abbfe17e91ecdf
|
7
|
+
data.tar.gz: fd7c224100e26d2cc70b64f7eb69f10b923d13a8601207cfddc2f0dcced6379866f4c60cf6ce3b96bbed7be0cebcddb6af7bc7037bb112b126986555a75d4c1b
|
data/lib/hrk/env.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
module Hrk
|
7
|
+
class Env
|
8
|
+
def remote= remote_name
|
9
|
+
if remote_name
|
10
|
+
socket_path.write remote_name unless remote == remote_name
|
11
|
+
else
|
12
|
+
socket_path.delete if remote?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def remote
|
17
|
+
socket_path.read if remote?
|
18
|
+
end
|
19
|
+
|
20
|
+
def remote?
|
21
|
+
socket_path.exist?
|
22
|
+
end
|
23
|
+
|
24
|
+
def tmp_path
|
25
|
+
Pathname.
|
26
|
+
new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, 'hrk')).
|
27
|
+
tap { |path| FileUtils.mkdir_p(path) unless path.exist? }
|
28
|
+
end
|
29
|
+
|
30
|
+
def socket_path
|
31
|
+
tmp_path.join Digest::MD5.hexdigest(`tty`)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/hrk/execute/command.rb
CHANGED
@@ -3,9 +3,22 @@ module Hrk
|
|
3
3
|
class Command
|
4
4
|
REMOTE_MATCHER = %r{\A(.+):\Z}
|
5
5
|
|
6
|
+
attr_reader :env
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@env = Hrk::Env.new
|
10
|
+
end
|
11
|
+
|
6
12
|
def call remote, *args
|
7
|
-
|
8
|
-
|
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(' '))
|
16
|
+
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(' '))
|
21
|
+
end
|
9
22
|
end
|
10
23
|
end
|
11
24
|
end
|
data/lib/hrk.rb
CHANGED
@@ -4,26 +4,104 @@ RSpec.describe Hrk::Execute::Command do
|
|
4
4
|
describe '#call' do
|
5
5
|
subject(:command) { Hrk::Execute::Command.new }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
let(:heroku) { double("Hrk::Heroku") }
|
8
|
+
before { allow(heroku).to receive(:call) }
|
9
|
+
before { allow(Hrk::Heroku).to receive(:new).and_return(heroku) }
|
10
10
|
|
11
|
-
|
12
|
-
before { allow(heroku).to receive(:call) }
|
13
|
-
before { allow(Hrk::Heroku).to receive(:new).and_return(heroku) }
|
11
|
+
before { allow(command.env).to receive(:remote=) }
|
14
12
|
|
15
|
-
|
13
|
+
context 'no remote was previously memorized' do
|
14
|
+
before { allow(command.env).to receive(:remote?).and_return(nil) }
|
16
15
|
|
17
|
-
|
18
|
-
|
16
|
+
describe 'standard case (a remote, a command)' do
|
17
|
+
let(:remote) { "remote-#{rand(1..9)}" }
|
18
|
+
let(:args) { %w(whatever that:may -b) }
|
19
|
+
|
20
|
+
[true, false].each do |result|
|
21
|
+
describe "when the command returns #{result}" do
|
22
|
+
before { allow(heroku).to receive(:call).and_return(result) }
|
23
|
+
|
24
|
+
it { expect(command.call("#{remote}:", *args)).to eq result }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'interactions' do
|
29
|
+
before { command.call "#{remote}:", *args }
|
30
|
+
|
31
|
+
it { expect(Hrk::Heroku).to have_received(:new).with(remote) }
|
32
|
+
it { expect(heroku).to have_received(:call).with("whatever that:may -b") }
|
33
|
+
it { expect(command.env).to have_received(:remote=).with(remote) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'edge cases (no remote or improper remote)' do
|
38
|
+
let(:other_args) { %W(something-#{rand(1..9)} or-another) }
|
39
|
+
|
40
|
+
before { expect(heroku).not_to receive(:call) }
|
41
|
+
before { expect(command.env).not_to receive(:remote=) }
|
42
|
+
|
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 }
|
47
|
+
end
|
19
48
|
end
|
20
49
|
|
21
|
-
|
22
|
-
let(:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
50
|
+
context 'a remote was previously memorized' do
|
51
|
+
let(:previous_remote) { "ye-olde-remote#{rand(1..9)}" }
|
52
|
+
before { allow(command.env).to receive(:remote).and_return(previous_remote) }
|
53
|
+
before { allow(command.env).to receive(:remote?).and_return(true) }
|
54
|
+
|
55
|
+
describe 'standard case (a remote, a command)' do
|
56
|
+
let(:remote) { "remote-#{rand(1..9)}" }
|
57
|
+
let(:args) { %w(whatever that:may -b) }
|
58
|
+
|
59
|
+
[true, false].each do |result|
|
60
|
+
describe "when the command returns #{result}" do
|
61
|
+
before { allow(heroku).to receive(:call).and_return(result) }
|
62
|
+
|
63
|
+
it { expect(command.call("#{remote}:", *args)).to eq result }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'interactions' do
|
68
|
+
before { command.call "#{remote}:", *args }
|
69
|
+
|
70
|
+
it { expect(Hrk::Heroku).to have_received(:new).with(remote) }
|
71
|
+
it { expect(heroku).to have_received(:call).with("whatever that:may -b") }
|
72
|
+
it { expect(command.env).to have_received(:remote=).with(remote) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'use previous remote' do
|
77
|
+
let(:args) { %w(whatever that:may -b) }
|
78
|
+
|
79
|
+
[true, false].each do |result|
|
80
|
+
describe "when the command returns #{result}" do
|
81
|
+
before { allow(heroku).to receive(:call).and_return(result) }
|
82
|
+
|
83
|
+
it { expect(command.call(":", *args)).to eq result }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'interactions' do
|
88
|
+
before { command.call ":", *args }
|
89
|
+
|
90
|
+
it { expect(Hrk::Heroku).to have_received(:new).with(previous_remote) }
|
91
|
+
it { expect(heroku).to have_received(:call).with("whatever that:may -b") }
|
92
|
+
end
|
93
|
+
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
|
27
105
|
end
|
28
106
|
end
|
29
107
|
end
|
data/spec/hrk/execute_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hrk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Belleville
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- README.md
|
63
63
|
- bin/hrk
|
64
64
|
- lib/hrk.rb
|
65
|
+
- lib/hrk/env.rb
|
65
66
|
- lib/hrk/execute.rb
|
66
67
|
- lib/hrk/execute/command.rb
|
67
68
|
- lib/hrk/execute/help.rb
|