ssh-host-lister 0.2.1 → 0.3.0

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
- SHA1:
3
- metadata.gz: 702affa345f01f04a1d19f1082b799f15072807c
4
- data.tar.gz: 0d80852e5c8b00c4f271e0676e114a9acdbf18cd
2
+ SHA256:
3
+ metadata.gz: 990e9e914a0b7bfef0cc9faa050facc6095a33a8b07ff25a753b7f2b57e14190
4
+ data.tar.gz: a5e711f556c084e8fd5c480910c72289ef0c4ba571a8b4247063f6fc2418882e
5
5
  SHA512:
6
- metadata.gz: 1a512e8a326ec81a0417d82cf91f6eef580e6d0266e56196c095f585f92ceda4b181b6e11b3e7123213638235d482e9de2cb4d497d0ebef1c807f83f5699e0ed
7
- data.tar.gz: 72fe87223649a8f3af001b3596513bc78a63a115c4eb836e84c0e55f31a0777707265d241f2a06c4790ff86be1dbf733cf1e111bb65ba3d50743fd5e94587e2f
6
+ metadata.gz: 3bf891ba73c69f18f292c0e7310216d7de8704bca875eb9edd17a52e79898466fe1223701cf72ba2a024cefde31247ddc6dac0f30578fbcdbd09711ca466ea4c
7
+ data.tar.gz: 451f13069375f981e1278c4dcdf323af7e3e2c9985ab2194021ebcebd5f3a4a583df992a6bc8054748dc37aa482b8aeed0fe4054fd76935ac75a0ebad4542a76
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SshConfig
4
- # SshHost represents a single Host entry in an ssh_config(5)
4
+ # Entry represents a single Host entry in an ssh_config(5)
5
5
  class Entry
6
6
  attr_reader :user
7
7
 
@@ -5,42 +5,46 @@ module SshConfig
5
5
  # For loading an ssh_config(5) file.
6
6
  class Loader
7
7
  def parse(str)
8
- pr = ParseRun.new
8
+ parse_lines(str.to_str.split(/[\n\r]+/))
9
+ end
9
10
 
10
- str
11
- .to_str
12
- .split(/[\n\r]+/)
13
- .each do |line|
11
+ def parse_lines(strings)
12
+ Array(strings).map(&:to_str).each do |line|
13
+ p_include(Regexp.last_match(1)) if line =~ /^\s*Include\s+(.*)/
14
+ p_host(Regexp.last_match(1)) if line =~ /^\s*Host\s+(.*)/
15
+ end
14
16
 
15
- pr.parse_host(Regexp.last_match(1)) if line =~ /^\s*Host\s+(.*)/
16
- end
17
+ results
18
+ end
17
19
 
18
- pr.results
20
+ def results
21
+ @results ||= {}
19
22
  end
20
- end
21
23
 
22
- # Internal method for parsing
23
- class ParseRun
24
- def parse_host(arg)
24
+ private
25
+
26
+ def p_host(arg)
25
27
  hosts = arg
26
28
  .split(/\s+/)
27
29
  .reject { |host| host =~ /^\d|%|\*/ }
28
30
 
29
- return if hosts.empty?
30
- entry = Entry.new(hosts)
31
- entry.distinct_names.each { |host| results[host] = entry }
31
+ add_entry(Entry.new(hosts)) unless hosts.empty?
32
32
  end
33
33
 
34
- def results
35
- @results ||= {}
34
+ def p_include(glob)
35
+ old_dir = Dir.pwd
36
+ begin
37
+ Dir.chdir File.expand_path('~/.ssh')
38
+ Dir[glob.chomp].each do |fname|
39
+ parse(File.read(fname))
40
+ end
41
+ ensure
42
+ Dir.chdir old_dir
43
+ end
36
44
  end
37
45
 
38
- private
39
-
40
- attr_writer :entry
41
-
42
- def entry
43
- @entry ||= nil
46
+ def add_entry(entry)
47
+ entry.distinct_names.each { |host| results[host] = entry }
44
48
  end
45
49
  end
46
50
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'ssh-host-lister'
6
- spec.version = '0.2.1'
6
+ spec.version = '0.3.0'
7
7
  spec.authors = ['Christian Höltje']
8
8
  spec.email = ['docwhat@gerf.org']
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssh-host-lister
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Höltje
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-10 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  version: '0'
198
198
  requirements: []
199
199
  rubyforge_project:
200
- rubygems_version: 2.4.5
200
+ rubygems_version: 2.7.2
201
201
  signing_key:
202
202
  specification_version: 4
203
203
  summary: Lists unique, short host names ssh_config(5)