poet 0.0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ tmp/aruba
data/History.txt ADDED
@@ -0,0 +1,11 @@
1
+ master
2
+
3
+ - testing with Aruba
4
+
5
+ - new CLI options --output and --dir
6
+
7
+ - Dropped CLI option --only
8
+
9
+ 0.0.1
10
+
11
+ - Initial release as gem
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ Lost in a long list of host stanzas in your `$HOME/.ssh/config`?
2
+
3
+ Fear not -- divide them up into several smaller files under `$HOME/.ssh/config.d/` and run `poet` to concatenate them into a single ssh_config.
4
+
5
+ `poet` does not overwrite your existing ssh_config. If you want to play with it, move your existing config out of the way.
6
+
7
+ Stanzas under `$HOME/.ssh/config.d/` with an extension of .disabled are ignored by poet. Every now and then, when you do need it, run `poet --with CONFIG` to explicitly include `CONFIG.disabled` in your generated ssh_config. You can even include several by running several '--with' options or using `--with CONFIG1,CONFIG2`.
8
+
9
+ If you only want an ssh_config from certain files, use `--only CONFIG` or `--only CONFIG1,CONFIG2`.
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'cucumber'
3
+ require 'cucumber/rake/task'
4
+
5
+ Cucumber::Rake::Task.new(:default, "Run tests")
data/bin/poet CHANGED
@@ -2,61 +2,63 @@
2
2
 
3
3
  require 'optparse'
4
4
 
5
- CONF_DIR = File.expand_path('~/.ssh/config.d')
6
- SSH_CONFIG = File.expand_path('~/.ssh/config')
7
5
  MAGIC_LINE = "# Generated by #{File.basename(__FILE__)}"
8
6
 
9
- options = {:verbose => false, :with => [], :only => []}
7
+ options = {
8
+ :ssh_config => File.expand_path('~/.ssh/config'),
9
+ :verbose => false,
10
+ :with => [],
11
+ :dir => File.expand_path('~/.ssh/config.d')
12
+ }
10
13
 
11
14
  optparse = OptionParser.new do|opts|
12
15
  opts.on('-h', '--help', 'Display this screen') do
13
16
  puts opts
14
17
  exit
15
18
  end
16
- opts.on('-v', '--verbose', 'Be verbose') do |file|
19
+ opts.on('-d', '--dir DIR', '') do |dir|
20
+ options[:dir] = File.expand_path(dir)
21
+ end
22
+ opts.on('-o', '--output FILE', '') do |file|
23
+ options[:ssh_config] = file
24
+ end
25
+ opts.on('-v', '--verbose', 'Be verbose') do
17
26
  options[:verbose] = true
18
27
  end
19
28
  opts.on('-w', '--with CONFIG', 'Include an otherwise disabled config file') do |file|
20
29
  options[:with] += file.split(',')
21
30
  options[:with].each{|file| puts "Including #{file} even if disabled..."}
22
31
  end
23
- opts.on('-o', '--only CONFIG', 'Use only given config files') do |file|
24
- options[:only] += file.split(',')
25
- options[:only].each{|file| puts "Using only #{file}..."}
26
- end
27
32
  end
28
33
  optparse.parse!
29
34
 
30
- if !File.directory?(CONF_DIR)
31
- puts "#{CONF_DIR} does not exist or is not a directory"
35
+ if !File.directory?(options[:dir])
36
+ $stderr.puts "#{options[:dir]} does not exist or is not a directory"
32
37
  Process.exit!(1)
33
38
  end
34
39
 
35
- if File.exists?(SSH_CONFIG) && File.new(SSH_CONFIG).gets == "#{MAGIC_LINE}\n"
36
- puts "Found generated ssh_config under #{SSH_CONFIG}. Overwriting..."
37
- elsif File.exists?(SSH_CONFIG)
38
- puts "Found hand-crafted ssh_config under #{SSH_CONFIG}. Please move it out of the way."
40
+ if File.exists?(options[:ssh_config]) && File.new(options[:ssh_config]).gets == "#{MAGIC_LINE}\n"
41
+ puts "Found generated ssh_config under #{options[:ssh_config]}. Overwriting..."
42
+ elsif File.exists?(options[:ssh_config])
43
+ $stderr.puts "Found hand-crafted ssh_config under #{options[:ssh_config]}. Please move it out of the way or specify a different output file with the -o option."
39
44
  Process.exit!(2)
40
45
  end
41
46
 
42
- File.open(SSH_CONFIG, 'w') do |ssh_config|
43
- ssh_config.puts(MAGIC_LINE)
44
- ssh_config.puts("# DO NOT EDIT THIS FILE")
45
- ssh_config.puts("# Create or modify files under #{CONF_DIR}/ instead")
47
+ files = Dir["#{options[:dir]}/**"].reject do |file|
48
+ file =~ /\.disabled$/ && !options[:with].include?("#{File.basename(file, '.disabled')}")
46
49
  end
47
50
 
48
- if options[:only].empty?
49
- files = Dir["#{CONF_DIR}/**"].reject do |file|
50
- file =~ /\.disabled$/ && !options[:with].include?("#{File.basename(file, '.disabled')}")
51
- end
52
- else
53
- files = Dir["#{CONF_DIR}/**"].select do |file|
54
- options[:only].include?(File.basename(file, '.disabled'))
55
- end
56
- end
51
+ files -= [options[:ssh_config]]
52
+
53
+ entries = []
57
54
 
58
55
  files.sort.each do |file|
59
- puts "Concatenating #{file}" if options[:verbose]
60
- %x(/bin/cat #{file} >> #{SSH_CONFIG})
61
- %x(echo >> #{SSH_CONFIG})
56
+ entries << File.read(file)
57
+ end
58
+
59
+ File.open(options[:ssh_config], 'w', 0600) do |ssh_config|
60
+ ssh_config.puts(MAGIC_LINE)
61
+ ssh_config.puts("# DO NOT EDIT THIS FILE")
62
+ ssh_config.puts("# Create or modify files under #{options[:dir]} instead")
63
+ ssh_config.puts(entries.join("\n"))
62
64
  end
@@ -0,0 +1,10 @@
1
+ Feature: Correct permissions
2
+ Scenario: User wants the generated file to work with SSH out-of-the-box.
3
+ Given a file named "permissions" with:
4
+ """
5
+ Host permissio.ns
6
+ User whatever
7
+ """
8
+ When I run `poet --dir . -o ssh_config`
9
+ And I run `ls -la ssh_config`
10
+ Then the file "ssh_config" should not be world-accessible
@@ -0,0 +1,30 @@
1
+ Feature: Running the program
2
+ Scenario: User runs the program
3
+ Given a file named "test" with:
4
+ """
5
+ Host te.st
6
+ User me
7
+ """
8
+ When I run `poet --dir . -o ssh_config`
9
+ Then the exit status should be 0
10
+ And the file "ssh_config" should contain "Host te.st"
11
+
12
+ Scenario: User wants her own files not to be overwritten
13
+ Given a file named "important" with:
14
+ """
15
+ This is absolutely vital information
16
+ """
17
+ When I run `poet --dir . -o important`
18
+ Then the output from "poet --dir . -o important" should contain "Found hand-crafted ssh_config"
19
+ And the exit status should not be 0
20
+ And the file "important" should contain "This is absolutely vital information"
21
+
22
+ Scenario: User wants sensible warnings
23
+ Given a file named "test" with:
24
+ """
25
+ Host te.st
26
+ User me
27
+ """
28
+ When I run `poet --dir missing -o ssh_config`
29
+ Then the output from "poet --dir missing -o ssh_config" should contain "missing does not exist"
30
+ And the exit status should not be 0
@@ -0,0 +1,45 @@
1
+ Feature: Selectively whitelist files
2
+ Scenario: Does not include disabled files by default
3
+ Given a file named "sometimes.disabled" with:
4
+ """
5
+ Host sometimes
6
+ User me
7
+ """
8
+ And a file named "always" with:
9
+ """
10
+ Host always
11
+ User me
12
+ """
13
+ When I run `poet --dir . -o ssh_config`
14
+ Then the file "ssh_config" should contain "Host always"
15
+ But the file "ssh_config" should not contain "Host sometimes"
16
+
17
+ Scenario: Does include disabled files when asked
18
+ Given a file named "sometimes.disabled" with:
19
+ """
20
+ Host sometimes
21
+ User me
22
+ """
23
+ And a file named "always" with:
24
+ """
25
+ Host always
26
+ User me
27
+ """
28
+ When I run `poet --dir . -o ssh_config -w sometimes`
29
+ Then the file "ssh_config" should contain "Host always"
30
+ And the file "ssh_config" should contain "Host sometimes"
31
+
32
+ Scenario: Allows to include several disabled files
33
+ Given a file named "sometimes.disabled" with:
34
+ """
35
+ Host sometimes
36
+ User me
37
+ """
38
+ Given a file named "almost_never.disabled" with:
39
+ """
40
+ Host almost_never
41
+ User me
42
+ """
43
+ When I run `poet --dir . -o ssh_config -w sometimes,almost_never`
44
+ Then the file "ssh_config" should contain "Host almost_never"
45
+ And the file "ssh_config" should contain "Host sometimes"
@@ -0,0 +1,3 @@
1
+ Then /^the file "([^"]*)" should not be world-accessible$/ do |filename|
2
+ step %Q(the output from "ls -la #{filename}" should contain "-rw-------")
3
+ end
@@ -0,0 +1,3 @@
1
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
2
+
3
+ require 'aruba/cucumber'
data/lib/poet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Poet
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2"
3
3
  end
data/poet.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
22
+ s.add_development_dependency "cucumber"
23
+ s.add_development_dependency "aruba"
24
+ s.add_development_dependency "rake"
24
25
  end
metadata CHANGED
@@ -1,76 +1,106 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: poet
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
13
- - "Andr\xC3\xA9 Wendt"
7
+ authors:
8
+ - André Wendt
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-03-29 00:00:00 +02:00
19
- default_executable:
20
- dependencies: []
21
-
22
- description: Split your longish ~/.ssh/config into files in ~/.ssh/config.d/ and let poet join them for you.
23
- email:
12
+ date: 2012-04-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cucumber
16
+ requirement: &70193940334220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70193940334220
25
+ - !ruby/object:Gem::Dependency
26
+ name: aruba
27
+ requirement: &70193940333780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70193940333780
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70193940333300 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70193940333300
47
+ description: Split your longish ~/.ssh/config into files in ~/.ssh/config.d/ and let
48
+ poet join them for you.
49
+ email:
24
50
  - awendt@freeshell.org
25
- executables:
51
+ executables:
26
52
  - poet
27
53
  extensions: []
28
-
29
54
  extra_rdoc_files: []
30
-
31
- files:
55
+ files:
32
56
  - .gitignore
33
57
  - Gemfile
58
+ - History.txt
34
59
  - MIT-LICENSE
35
- - README
60
+ - README.md
36
61
  - Rakefile
37
62
  - bin/poet
63
+ - features/permissions.feature
64
+ - features/running.feature
65
+ - features/selective_files.feature
66
+ - features/step_definitions/permissions_steps.rb
67
+ - features/support/env.rb
38
68
  - lib/poet.rb
39
69
  - lib/poet/version.rb
40
70
  - poet.gemspec
41
- has_rdoc: true
42
71
  homepage: https://github.com/awendt/poet
43
72
  licenses: []
44
-
45
73
  post_install_message:
46
74
  rdoc_options: []
47
-
48
- require_paths:
75
+ require_paths:
49
76
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
77
+ required_ruby_version: !ruby/object:Gem::Requirement
51
78
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ segments:
57
84
  - 0
58
- version: "0"
59
- required_rubygems_version: !ruby/object:Gem::Requirement
85
+ hash: 3681220582875752418
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
87
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
66
93
  - 0
67
- version: "0"
94
+ hash: 3681220582875752418
68
95
  requirements: []
69
-
70
96
  rubyforge_project: poet
71
- rubygems_version: 1.6.2
97
+ rubygems_version: 1.8.11
72
98
  signing_key:
73
99
  specification_version: 3
74
100
  summary: Poet concatenates stanzas
75
- test_files: []
76
-
101
+ test_files:
102
+ - features/permissions.feature
103
+ - features/running.feature
104
+ - features/selective_files.feature
105
+ - features/step_definitions/permissions_steps.rb
106
+ - features/support/env.rb
data/README DELETED
@@ -1,9 +0,0 @@
1
- Lost in a long list of host stanzas in your ssh_config?
2
-
3
- Fear not -- divide them up into several smaller files under $HOME/.ssh/config.d/ and run 'ssh-confgen' to concatenate them into a single ssh_config.
4
-
5
- 'ssh-confgen' does not overwrite your existing ssh_config. If you want to play with it, move your existing config out of the way.
6
-
7
- Stanzas under $HOME/.ssh/config.d/ with an extension of .disabled are ignored by ssh-confgen. Every now and then, when you do need it, run 'ssh-confgen --with CONFIG' to explicitly include CONFIG.disabled in your generated ssh_config. You can even include several by running several '--with' options or using '--with CONFIG1,CONFIG2'.
8
-
9
- If you only want an ssh_config from certain files, use '--only CONFIG' or '--only CONFIG1,CONFIG2'.