hss 0.2.9 → 0.2.10

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: a3581eeed1ac365b90cffbdbfe549635ed110864
4
- data.tar.gz: 57f02e1a14a2bba09e5e5dbb2471173dba77136b
3
+ metadata.gz: 293ae1e185a7269abc0019beaff526fc02bed9ed
4
+ data.tar.gz: 044f94139c54a7254e2f1ff4fa36da4966f42e38
5
5
  SHA512:
6
- metadata.gz: 45354b0f2d9d9cf8f52ccb8dc88499b40641f64e540d30a94a4edeb2d7e133e8c742a669a5a770593d5d06df87dd3d46d5942e15fc3286259ec1d52a7b101936
7
- data.tar.gz: f944b7dbf95e7087d668649ff0cff6d974d67dfb808cd9c7e39c054232218c5552331c7cd115b2a7868884b38d81ae43b15477028e81c9802652d907afe01d82
6
+ metadata.gz: 1fd26cacaa7d64fabc82c7e86b06d36f230c21f2b1c8dca08af4b17c480955d42b8df476db7a36527db5b95d35ca6a4caf3b4cc22478373b78a29df08c2cedfd
7
+ data.tar.gz: 3c9cd1b271b305c5828ad4b4e48d47d5c7b18bc6fa776329c8214ccd685f0e58f00405dfc160bcd605c00bb932d621ceec47807d2294f3cead69441f2a239804
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- Excludes:
2
+ Exclude:
3
3
  - spec/test/bad_helpers/module.rb
4
4
  Encoding:
5
5
  Enabled: false
data/.travis.yml CHANGED
@@ -1,17 +1,18 @@
1
1
  before_script:
2
- - "ssh-keygen -N '' -C 'build-test' -f ~/.ssh/id_rsa"
3
- - "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"
2
+ - ssh-keygen -N '' -C 'build-test' -f ~/.ssh/id_rsa
3
+ - cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
4
4
  language: ruby
5
5
  cache: bundler
6
6
  rvm:
7
- - 2.1.0
8
- - 2.0.0
9
- - 1.9.3
7
+ - 2.1.2
8
+ - 2.1.1
9
+ - 2.1.0
10
+ - 2.0.0
11
+ - 1.9.3
10
12
  notifications:
11
13
  email: false
12
14
  irc:
13
15
  channels:
14
- - ircs://irc.oftc.net:6697#akerl
15
- channel_key: sekrit
16
+ - secure: Z3ypJ8MOTwGDrwpqR6mHidleA9jAp1cCV05ElH5VjS4fuWWZ3uBAhFVssKjfbB9fQl+4nesJpHO5cfOAXNBX1UO1w7d87692zgImux1MRo2P5n2sR+yGO/ZTtYyCF0oQF2u1RU4bybI91f8mX69tcM4f+Ggi3yjQvbubnaXVPn0=
16
17
  template:
17
- - '%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}'
18
+ - "%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}"
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2013 Les Aker
3
+ Copyright (c) 2014 Les Aker
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  hss
2
2
  =========
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/hss.png)](http://badge.fury.io/rb/hss)
5
- [![Dependency Status](https://gemnasium.com/akerl/hss.png)](https://gemnasium.com/akerl/hss)
6
- [![Code Climate](https://codeclimate.com/github/akerl/hss.png)](https://codeclimate.com/github/akerl/hss)
7
- [![Coverage Status](https://coveralls.io/repos/akerl/hss/badge.png)](https://coveralls.io/r/akerl/hss)
8
- [![Build Status](https://travis-ci.org/akerl/hss.png?branch=master)](https://travis-ci.org/akerl/hss)
4
+ [![Gem Version](https://img.shields.io/gem/v/hss.svg)](https://rubygems.org/gems/hss)
5
+ [![Dependency Status](https://img.shields.io/gemnasium/akerl/hss.svg)](https://gemnasium.com/akerl/hss)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/akerl/hss.svg)](https://codeclimate.com/github/akerl/hss)
7
+ [![Coverage Status](https://img.shields.io/coveralls/akerl/hss.svg)](https://coveralls.io/r/akerl/hss)
8
+ [![Build Status](https://img.shields.io/travis/akerl/hss.svg)](https://travis-ci.org/akerl/hss)
9
+ [![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://tldrlegal.com/license/mit-license)
9
10
 
10
11
  SSH helper that uses regex and fancy expansion to dynamically manage SSH shortcuts
11
12
 
data/Rakefile CHANGED
@@ -2,24 +2,13 @@ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'rubocop/rake_task'
4
4
 
5
- desc 'Update bundle'
6
- task :bundle do
7
- `bundle update`
8
- end
9
-
10
5
  desc 'Run tests'
11
6
  RSpec::Core::RakeTask.new(:spec)
12
7
 
13
- desc 'Run Rubocop on the gem'
14
- Rubocop::RakeTask.new(:rubocop) do |task|
8
+ desc 'Run RuboCop on the gem'
9
+ RuboCop::RakeTask.new(:rubocop) do |task|
15
10
  task.patterns = ['lib/**/*.rb', 'spec/*.rb', 'spec/helpers/*.rb', 'bin/*']
16
11
  task.fail_on_error = true
17
12
  end
18
13
 
19
- desc 'Run travis-lint on .travis.yml'
20
- task :travislint do
21
- print 'There may be an issue with your .travis.yml' unless system('travis-lint')
22
- end
23
-
24
- task :default => [:spec, :travislint, :rubocop, :build, :install]
25
- task :release => [:bundle]
14
+ task :default => [:spec, :rubocop, :build, :install]
data/hss.gemspec CHANGED
@@ -16,12 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files spec/*`.split
17
17
  s.executables = ['hss']
18
18
 
19
- s.add_development_dependency 'rubocop'
20
- s.add_development_dependency 'travis-lint'
21
- s.add_development_dependency 'rake'
22
- s.add_development_dependency 'coveralls'
23
- s.add_development_dependency 'rspec'
24
- s.add_development_dependency 'fuubar'
25
- s.add_development_dependency 'parser'
19
+ s.add_development_dependency 'rubocop', '~> 0.23.0'
20
+ s.add_development_dependency 'rake', '~> 10.3.2'
21
+ s.add_development_dependency 'coveralls', '~> 0.7.0'
22
+ s.add_development_dependency 'rspec', '~> 3.0.0'
23
+ s.add_development_dependency 'fuubar', '~> 2.0.0.rc1'
26
24
  end
27
-
@@ -1,15 +1,17 @@
1
1
  require 'English'
2
2
 
3
- ##
4
- # Runs a shell command and returns the output
5
- class HSS::Parser
6
- private
3
+ module HSS
4
+ ##
5
+ # Runs a shell command and returns the output
6
+ class Parser
7
+ private
7
8
 
8
- def command(input)
9
- result = IO.popen(input) { |cmd| cmd.read.chomp }
10
- fail "Command failed: #{input}" unless $CHILD_STATUS == 0
11
- result
12
- rescue Errno::ENOENT
13
- raise "Command not found: #{input}"
9
+ def command(input)
10
+ result = IO.popen(input) { |cmd| cmd.read.chomp }
11
+ fail "Command failed: #{input}" unless $CHILD_STATUS == 0
12
+ result
13
+ rescue Errno::ENOENT
14
+ raise "Command not found: #{input}"
15
+ end
14
16
  end
15
17
  end
@@ -1,9 +1,11 @@
1
- ##
2
- # Provides a helper to have default values
3
- class HSS::Parser
4
- private
1
+ module HSS
2
+ ##
3
+ # Provides a helper to have default values
4
+ class Parser
5
+ private
5
6
 
6
- def default(a, b)
7
- a.nil? || a.empty? ? b : a
7
+ def default(a, b)
8
+ a.nil? || a.empty? ? b : a
9
+ end
8
10
  end
9
11
  end
@@ -1,12 +1,14 @@
1
- ##
2
- # Expand a shortcode based the config hash
3
- class HSS::Parser
4
- private
1
+ module HSS
2
+ ##
3
+ # Expand a shortcode based the config hash
4
+ class Parser
5
+ private
5
6
 
6
- def expand(input)
7
- @config['expansions'].each do |long, shorts|
8
- return long if shorts.include? input
7
+ def expand(input)
8
+ @config['expansions'].each do |long, shorts|
9
+ return long if shorts.include? input
10
+ end
11
+ fail NameError, "No expansion found for: #{input}"
9
12
  end
10
- fail NameError, "No expansion found for: #{input}"
11
13
  end
12
14
  end
@@ -1,20 +1,22 @@
1
1
  require 'yaml'
2
2
 
3
- ##
4
- # Load values from an external YAML hash
5
- class HSS::Parser
6
- private
3
+ module HSS
4
+ ##
5
+ # Load values from an external YAML hash
6
+ class Parser
7
+ private
7
8
 
8
- def external(source, key)
9
- begin
10
- config = open(File.expand_path(source)) { |f| YAML.load f.read }
11
- rescue Psych::SyntaxError, Errno::ENOENT
12
- raise "Failed to open YAML file: #{source}"
13
- end
14
- begin
15
- key.split('.').reduce(config) { |a, e| a[e] } || fail
16
- rescue
17
- raise NameError, "Key not found in YAML: #{key}"
9
+ def external(source, key)
10
+ begin
11
+ config = open(File.expand_path(source)) { |f| YAML.load f.read }
12
+ rescue Psych::SyntaxError, Errno::ENOENT
13
+ raise "Failed to open YAML file: #{source}"
14
+ end
15
+ begin
16
+ key.split('.').reduce(config) { |a, e| a[e] } || fail
17
+ rescue
18
+ raise NameError, "Key not found in YAML: #{key}"
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -1,11 +1,13 @@
1
- ##
2
- # Allow shortcut expansion from the config
3
- class HSS::Parser
4
- private
1
+ module HSS
2
+ ##
3
+ # Allow shortcut expansion from the config
4
+ class Parser
5
+ private
5
6
 
6
- def shortcut(input)
7
- @config['shortcuts'][input] || fail
8
- rescue
9
- raise NameError, "Shortcut does not exist #{input}"
7
+ def shortcut(input)
8
+ @config['shortcuts'][input] || fail
9
+ rescue
10
+ raise NameError, "Shortcut does not exist #{input}"
11
+ end
10
12
  end
11
13
  end
data/lib/hss.rb CHANGED
@@ -50,7 +50,8 @@ module HSS
50
50
 
51
51
  def load_config(config_path = nil)
52
52
  path = File.expand_path(config_path || HSS::DEFAULT_CONFIG)
53
- @config = YAML.load open(path).read
53
+ files = path.split(':').map { |x| YAML.load File.read x }
54
+ @config = files.reverse.reduce(&:deep_merge)
54
55
  @patterns = @config.delete('patterns') || fail
55
56
  rescue Psych::SyntaxError, RuntimeError, Errno::ENOENT
56
57
  raise "Failed to load config: #{config_path}"
@@ -89,7 +90,7 @@ module HSS
89
90
 
90
91
  def check(input, short_form)
91
92
  return false unless input.match short_form
92
- x = Regexp.last_match # rubocop:disable UselessSetterCall
93
+ x = Regexp.last_match # rubocop:disable UselessAssignment
93
94
  @match_data = binding
94
95
  true
95
96
  end
@@ -103,3 +104,22 @@ module HSS
103
104
  end
104
105
  end
105
106
  end
107
+
108
+ ##
109
+ # Time to monkeypatch Hash to support smarter merging
110
+ class Hash
111
+ ##
112
+ # Define a method to merge config hashes
113
+
114
+ def deep_merge(new)
115
+ merge(new) do |_, oldval, newval|
116
+ if oldval.is_a? Hash
117
+ deep_merge oldval, newval
118
+ elsif oldval.is_a? Array
119
+ oldval + newval
120
+ else
121
+ newval
122
+ end
123
+ end
124
+ end
125
+ end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  ##
2
2
  # Define the version
3
3
  module HSS
4
- VERSION = '0.2.9'
4
+ VERSION = '0.2.10'
5
5
  end
data/spec/bin_spec.rb CHANGED
@@ -21,6 +21,6 @@ describe 'HSS script' do
21
21
  end
22
22
  it 'connects via SCP' do
23
23
  `scp -S hss spec/test/config.yml l:#{Dir.pwd}/scp_test`
24
- expect(File.exists? 'scp_test').to be_true
24
+ expect(File.exist? 'scp_test').to be_truthy
25
25
  end
26
26
  end
data/spec/hss_spec.rb CHANGED
@@ -26,6 +26,7 @@ describe HSS do
26
26
  describe '#load_config' do
27
27
  let(:invalid) { 'spec/test/invalid.yml' }
28
28
  let(:incomplete) { 'spec/test/incomplete.yml' }
29
+ let(:other) { 'spec/test/other.yml' }
29
30
 
30
31
  it 'loads the specified YAML file' do
31
32
  expect(handler.config).to be_an_instance_of Hash
@@ -41,18 +42,27 @@ describe HSS do
41
42
  expect { HSS::Handler.new 'foobaz' }.to raise_error RuntimeError
42
43
  end
43
44
  it 'uses the default config if none is provided' do
44
- if File.exists? File.expand_path(HSS::DEFAULT_CONFIG)
45
+ if File.exist? File.expand_path(HSS::DEFAULT_CONFIG)
45
46
  expect(HSS::Handler.new.config).to be_an_instance_of Hash
46
47
  else
47
48
  expect { HSS::Handler.new }.to raise_error RuntimeError
48
49
  end
49
50
  end
51
+ it 'supports loading multiple configs' do
52
+ handler = HSS::Handler.new(config: "#{config}:#{other}")
53
+ expect(handler.patterns.map { |x| x['note'] }).to include(
54
+ 'Basic test',
55
+ 'Other test',
56
+ 'Connection test'
57
+ )
58
+ expect(handler.patterns.first['long']).to match(/^new/)
59
+ end
50
60
  end
51
61
 
52
62
  describe '#load_helpers' do
53
63
  it 'loads helper modules' do
54
64
  expect(handler.helpers).to be_an_instance_of Array
55
- expect(handler.helpers).to have_at_least(3).items
65
+ expect(handler.helpers.size).to be >= 3
56
66
  end
57
67
  it 'accepts a helper_path' do
58
68
  h = HSS::Handler.new(config: config, helpers: 'spec/test/good_helpers')
@@ -104,8 +114,8 @@ describe HSS do
104
114
 
105
115
  describe '#check' do
106
116
  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
117
+ expect(parser.check('a', '[a-z]')).to be_truthy
118
+ expect(parser.check('1', '[a-z]')).to be_falsey
109
119
  end
110
120
  end
111
121
 
@@ -0,0 +1,11 @@
1
+ ---
2
+ patterns:
3
+ - note: Basic test
4
+ example: g -> github
5
+ short: '^g$'
6
+ long: 'new@github.com'
7
+ - note: Other test
8
+ example: z -> other
9
+ short: '^z$'
10
+ long: 'other@example.com'
11
+ ...
metadata CHANGED
@@ -1,113 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-11 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.23.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: travis-lint
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: 0.23.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: 10.3.2
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: 10.3.2
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: coveralls
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ">="
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '0'
47
+ version: 0.7.0
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ">="
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: 0.7.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: 3.0.0
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: 3.0.0
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: fuubar
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: parser
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
73
+ - - "~>"
102
74
  - !ruby/object:Gem::Version
103
- version: '0'
75
+ version: 2.0.0.rc1
104
76
  type: :development
105
77
  prerelease: false
106
78
  version_requirements: !ruby/object:Gem::Requirement
107
79
  requirements:
108
- - - ">="
80
+ - - "~>"
109
81
  - !ruby/object:Gem::Version
110
- version: '0'
82
+ version: 2.0.0.rc1
111
83
  description: Regex-based SSH shortcut tool
112
84
  email: me@lesaker.org
113
85
  executables:
@@ -147,6 +119,7 @@ files:
147
119
  - spec/test/good_helpers/shortcut.rb
148
120
  - spec/test/incomplete.yml
149
121
  - spec/test/invalid.yml
122
+ - spec/test/other.yml
150
123
  homepage: https://github.com/akerl/hss
151
124
  licenses:
152
125
  - MIT
@@ -187,3 +160,5 @@ test_files:
187
160
  - spec/test/good_helpers/shortcut.rb
188
161
  - spec/test/incomplete.yml
189
162
  - spec/test/invalid.yml
163
+ - spec/test/other.yml
164
+ has_rdoc: