hss 0.2.4 → 0.2.5
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/.gitignore +3 -2
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +14 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +71 -0
- data/README.md +44 -22
- data/Rakefile +19 -1
- data/bin/hss +14 -15
- data/hss.gemspec +12 -2
- data/lib/helpers/command.rb +14 -4
- data/lib/helpers/default.rb +8 -4
- data/lib/helpers/expand.rb +10 -4
- data/lib/helpers/external.rb +21 -0
- data/lib/helpers/shortcut.rb +10 -4
- data/lib/hss.rb +91 -51
- data/lib/version.rb +6 -0
- data/spec/helpers/command_spec.rb +27 -0
- data/spec/helpers/default_spec.rb +15 -0
- data/spec/helpers/expand_spec.rb +18 -0
- data/spec/helpers/external_spec.rb +28 -0
- data/spec/helpers/shortcut_spec.rb +18 -0
- data/spec/hss_spec.rb +120 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/test/bad_helpers/module.rb +2 -0
- data/spec/test/config.yml +73 -0
- data/spec/test/external_test.yml +7 -0
- data/spec/test/good_helpers/default.rb +8 -0
- data/spec/test/good_helpers/shortcut.rb +8 -0
- data/spec/test/incomplete.yml +6 -0
- data/spec/test/invalid.yml +8 -0
- data/vendor/cache/ast-1.1.0.gem +0 -0
- data/vendor/cache/coveralls-0.7.0.gem +0 -0
- data/vendor/cache/diff-lcs-1.2.5.gem +0 -0
- data/vendor/cache/docile-1.1.0.gem +0 -0
- data/vendor/cache/fuubar-1.2.1.gem +0 -0
- data/vendor/cache/hashr-0.0.22.gem +0 -0
- data/vendor/cache/mime-types-2.0.gem +0 -0
- data/vendor/cache/multi_json-1.8.2.gem +0 -0
- data/vendor/cache/parser-2.1.0.pre1.gem +0 -0
- data/vendor/cache/powerpack-0.0.9.gem +0 -0
- data/vendor/cache/rainbow-1.1.4.gem +0 -0
- data/vendor/cache/rake-10.1.0.gem +0 -0
- data/vendor/cache/rest-client-1.6.7.gem +0 -0
- data/vendor/cache/rspec-2.14.1.gem +0 -0
- data/vendor/cache/rspec-core-2.14.7.gem +0 -0
- data/vendor/cache/rspec-expectations-2.14.4.gem +0 -0
- data/vendor/cache/rspec-instafail-0.2.4.gem +0 -0
- data/vendor/cache/rspec-mocks-2.14.4.gem +0 -0
- data/vendor/cache/rubocop-0.15.0.gem +0 -0
- data/vendor/cache/ruby-progressbar-1.2.0.gem +0 -0
- data/vendor/cache/simplecov-0.8.2.gem +0 -0
- data/vendor/cache/simplecov-html-0.8.0.gem +0 -0
- data/vendor/cache/slop-3.4.7.gem +0 -0
- data/vendor/cache/term-ansicolor-1.2.2.gem +0 -0
- data/vendor/cache/thor-0.18.1.gem +0 -0
- data/vendor/cache/tins-0.13.1.gem +0 -0
- data/vendor/cache/travis-lint-1.7.0.gem +0 -0
- metadata +167 -8
- data/test.conf +0 -17
data/lib/version.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HSS::Parser do
|
4
|
+
let(:config) { 'spec/test/config.yml' }
|
5
|
+
let(:handler) { HSS::Handler.new config }
|
6
|
+
|
7
|
+
describe '#command' do
|
8
|
+
it 'runs shell commands' do
|
9
|
+
expect(handler.handle 'cmd_bar').to eql 'bar@example.org'
|
10
|
+
end
|
11
|
+
context 'if the command is invalid' do
|
12
|
+
it 'raises an error' do
|
13
|
+
expect { handler.handle 'failcmd_zsxdcf' }.to raise_error RuntimeError
|
14
|
+
end
|
15
|
+
end
|
16
|
+
context 'if the command is not executable' do
|
17
|
+
it 'raises an error' do
|
18
|
+
expect { handler.handle 'failcmd_LICENSE' }.to raise_error RuntimeError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
context 'if the command fails' do
|
22
|
+
it 'raises an error' do
|
23
|
+
expect { handler.handle 'failcmd_false' }.to raise_error RuntimeError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HSS::Parser do
|
4
|
+
let(:config) { 'spec/test/config.yml' }
|
5
|
+
let(:handler) { HSS::Handler.new config }
|
6
|
+
|
7
|
+
describe '#default' do
|
8
|
+
it 'uses the provided value if set' do
|
9
|
+
expect(handler.handle 'def_77').to eql 'chose_77'
|
10
|
+
end
|
11
|
+
it 'uses the default if the value is unset' do
|
12
|
+
expect(handler.handle 'def_').to eql 'chose_10'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HSS::Parser do
|
4
|
+
let(:config) { 'spec/test/config.yml' }
|
5
|
+
let(:handler) { HSS::Handler.new config }
|
6
|
+
|
7
|
+
describe '#expand' do
|
8
|
+
it 'matches keywords in a mapping' do
|
9
|
+
expect(handler.handle 'exp_a').to eql 'exp_alpha'
|
10
|
+
expect(handler.handle 'exp_2').to eql 'exp_beta'
|
11
|
+
end
|
12
|
+
context 'when no match is found' do
|
13
|
+
it 'raises an error' do
|
14
|
+
expect { handler.handle 'exp_c' }.to raise_error NameError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HSS::Parser do
|
4
|
+
let(:config) { 'spec/test/config.yml' }
|
5
|
+
let(:handler) { HSS::Handler.new config }
|
6
|
+
|
7
|
+
describe '#external' do
|
8
|
+
it 'reads values from a YAML file' do
|
9
|
+
expect(handler.handle 'ext_test.first.color').to eql 'external_blue'
|
10
|
+
end
|
11
|
+
context 'when a key is not found' do
|
12
|
+
it 'raises an error' do
|
13
|
+
expect { handler.handle 'ext_test.three' }.to raise_error NameError
|
14
|
+
expect { handler.handle 'ext_test.five.tree' }.to raise_error NameError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
context 'when the source does not exist' do
|
18
|
+
it 'raises an error' do
|
19
|
+
expect { handler.handle 'failext_abcd' }.to raise_error RuntimeError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
context 'when the source YAML is invalid' do
|
23
|
+
it 'raises an error' do
|
24
|
+
expect { handler.handle 'failext_invalid' }.to raise_error RuntimeError
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HSS::Parser do
|
4
|
+
let(:config) { 'spec/test/config.yml' }
|
5
|
+
let(:handler) { HSS::Handler.new config }
|
6
|
+
|
7
|
+
describe '#shortcut' do
|
8
|
+
it 'expands shortcut text' do
|
9
|
+
expect(handler.handle 'short_a').to eql 'short_ALPHA'
|
10
|
+
expect(handler.handle 'short_b').to eql 'short_BETA'
|
11
|
+
end
|
12
|
+
context 'when an invalid shortcut is used' do
|
13
|
+
it 'raises an error' do
|
14
|
+
expect { handler.handle 'short_z' }.to raise_error NameError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/hss_spec.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HSS do
|
4
|
+
let(:config) { 'spec/test/config.yml' }
|
5
|
+
let(:handler) { HSS::Handler.new config }
|
6
|
+
|
7
|
+
describe '::VERSION' do
|
8
|
+
it 'follows the semantic version scheme' do
|
9
|
+
expect(HSS::VERSION).to match /\d+\.\d+\.\d+/
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#initialize' do
|
14
|
+
it 'creates Handler objects' do
|
15
|
+
expect(HSS.new(config: config)).to be_an_instance_of HSS::Handler
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe HSS::Handler do
|
20
|
+
describe '#initialize' do
|
21
|
+
it 'creates Handler objects' do
|
22
|
+
expect(handler).to be_an_instance_of HSS::Handler
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#load_config' do
|
27
|
+
let(:invalid) { 'spec/test/invalid.yml' }
|
28
|
+
let(:incomplete) { 'spec/test/incomplete.yml' }
|
29
|
+
|
30
|
+
it 'loads the specified YAML file' do
|
31
|
+
expect(handler.config).to be_an_instance_of Hash
|
32
|
+
expect(handler.patterns).to be_an_instance_of Array
|
33
|
+
end
|
34
|
+
it 'raises an error for invalid configs' do
|
35
|
+
expect { HSS::Handler.new invalid }.to raise_error RuntimeError
|
36
|
+
end
|
37
|
+
it 'raises an error for configs without patterns' do
|
38
|
+
expect { HSS::Handler.new incomplete }.to raise_error RuntimeError
|
39
|
+
end
|
40
|
+
it 'raises an error if the config does not exist' do
|
41
|
+
expect { HSS::Handler.new 'foobaz' }.to raise_error RuntimeError
|
42
|
+
end
|
43
|
+
it 'uses the default config if none is provided' do
|
44
|
+
if File.exists? File.expand_path(HSS::DEFAULT_CONFIG)
|
45
|
+
expect(HSS::Handler.new.config).to be_an_instance_of Hash
|
46
|
+
else
|
47
|
+
expect { HSS::Handler.new }.to raise_error RuntimeError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#load_helpers' do
|
53
|
+
it 'loads helper modules' do
|
54
|
+
expect(handler.helpers).to be_an_instance_of Array
|
55
|
+
expect(handler.helpers).to have_at_least(3).items
|
56
|
+
end
|
57
|
+
it 'accepts a helper_path' do
|
58
|
+
h = HSS::Handler.new(config: config, helpers: 'spec/test/good_helpers')
|
59
|
+
expect(h.helpers).to be_an_instance_of Array
|
60
|
+
expect(h.helpers.size).to eql 2
|
61
|
+
end
|
62
|
+
it 'raises LoadError if loading modules fails' do
|
63
|
+
options = { config: config, helpers: 'spec/test/bad_helpers' }
|
64
|
+
expect { HSS::Handler.new options }.to raise_error LoadError
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#handle' do
|
69
|
+
it 'matches input to patterns' do
|
70
|
+
expect(handler.handle 'g').to eql 'git@github.com'
|
71
|
+
end
|
72
|
+
it 'supports regex capturing' do
|
73
|
+
expect(handler.handle 'cap99').to eql 'server99.example.org'
|
74
|
+
end
|
75
|
+
it 'supports named captures' do
|
76
|
+
expect(handler.handle 'name_a').to eql 'name_ALPHA'
|
77
|
+
end
|
78
|
+
it 'raises an error if no match is found' do
|
79
|
+
expect { handler.handle 'x' }.to raise_exception RuntimeError
|
80
|
+
end
|
81
|
+
it 'supports combination of helpers' do
|
82
|
+
expect(handler.handle 'bar__1_b').to eql 'bar_9_alpha_BETA'
|
83
|
+
end
|
84
|
+
it 'supports shallow nested operations' do
|
85
|
+
expect(handler.handle 'nest_a').to eql 'winner'
|
86
|
+
end
|
87
|
+
it 'supports deep nested operations' do
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe HSS::Parser do
|
94
|
+
let(:parser) { HSS::Parser.new(key: 'value') }
|
95
|
+
|
96
|
+
describe '#initialize' do
|
97
|
+
it 'creates a Parser' do
|
98
|
+
expect(parser).to be_an_instance_of HSS::Parser
|
99
|
+
end
|
100
|
+
it 'stores the config for later use' do
|
101
|
+
expect(parser.parse('#{@config[:key]}')).to eql 'value'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#check' do
|
106
|
+
it 'compares an input to a short form' do
|
107
|
+
expect(parser.check('a', '[a-z]')).to be_true
|
108
|
+
expect(parser.check('1', '[a-z]')).to be_false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#parse' do
|
113
|
+
it 'evaluates a long_form using the stored scope' do
|
114
|
+
expect(parser.parse('#{$1}')).to eql ''
|
115
|
+
parser.check('winner', '([a-z]+)')
|
116
|
+
expect(parser.parse('#{$1}')).to eql 'winner'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
---
|
2
|
+
patterns:
|
3
|
+
- note: Basic test
|
4
|
+
example: g -> github
|
5
|
+
short: '^g$'
|
6
|
+
long: 'git@github.com'
|
7
|
+
- note: Capture test
|
8
|
+
example: cap1 -> server1.example.org
|
9
|
+
short: '^cap(\d+)$'
|
10
|
+
long: 'server#{$1}.example.org'
|
11
|
+
- note: Named capture test
|
12
|
+
example: name_a -> ALPHA
|
13
|
+
short: '^name_(?<var>\w+)$'
|
14
|
+
long: 'name_#{shortcut(x["var"])}'
|
15
|
+
- note: Command test
|
16
|
+
example: cmdfoo -> "foo"
|
17
|
+
short: '^cmd_([a-z]+)$'
|
18
|
+
long: '#{command("echo " + $1)}@example.org'
|
19
|
+
- note: Command failure test
|
20
|
+
example: failcmd_foobar -> Error
|
21
|
+
short: '^failcmd_([a-zA-Z]+)$'
|
22
|
+
long: '#{command($1)}'
|
23
|
+
- note: Default test
|
24
|
+
example: def -> chose_10
|
25
|
+
short: '^def_(\d*)$'
|
26
|
+
long: 'chose_#{default($1, "10")}'
|
27
|
+
- note: Expansion test
|
28
|
+
example: expa -> exp_alpha
|
29
|
+
short: '^exp_(\w+)'
|
30
|
+
long: 'exp_#{expand($1)}'
|
31
|
+
- note: External test
|
32
|
+
example: ext_test.first.color -> external_red
|
33
|
+
short: '^ext_([a-z.]+)$'
|
34
|
+
long: 'external_#{external("spec/test/external_test.yml", $1)}'
|
35
|
+
- note: External failure test
|
36
|
+
example: failext_foo -> Error
|
37
|
+
short: '^failext_([a-z]+)$'
|
38
|
+
long: 'external_#{external("spec/test/" + $1 + ".yml", "tree.frog")}'
|
39
|
+
- note: Shortcut test
|
40
|
+
example: short_a -> short_ALPHA
|
41
|
+
short: '^short_([a-z])$'
|
42
|
+
long: 'short_#{shortcut($1)}'
|
43
|
+
- note: Mixed test
|
44
|
+
example: bar__1_b -> bar_9_alpha_BETA
|
45
|
+
short: '([^_]+)_([^_]*)_([^_]+)_([^_]+)'
|
46
|
+
long: '#{command("echo " + $1)}_#{default($2, "9")}_#{expand($3)}_#{shortcut($4)}'
|
47
|
+
- note: Shallow nested test
|
48
|
+
example: nest_a -> winner
|
49
|
+
short: '^nest_([a-z])$'
|
50
|
+
long: '#{shortcut(expand($1))}'
|
51
|
+
- note: Deep nested test
|
52
|
+
example: deep_cat_c -> CHARLIE
|
53
|
+
short: '^deep_(?<pet>[a-z]+)_([a-z]+)$'
|
54
|
+
long: '#{expand(x["pet"])}'
|
55
|
+
expansions:
|
56
|
+
alpha:
|
57
|
+
- a
|
58
|
+
- '1'
|
59
|
+
- alph
|
60
|
+
beta:
|
61
|
+
- b
|
62
|
+
- '2'
|
63
|
+
- bet
|
64
|
+
'#{shortcut($2)':
|
65
|
+
- fish
|
66
|
+
- dog
|
67
|
+
- cat
|
68
|
+
shortcuts:
|
69
|
+
a: ALPHA
|
70
|
+
b: BETA
|
71
|
+
c: CHARLIE
|
72
|
+
alpha: winner
|
73
|
+
...
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|