chef_attrdoc 1.0.3 → 1.1.0

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.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
- Gemfile.lock
1
+ Gemfile.lock
2
+ *.gem
3
+ .bundle
@@ -0,0 +1,2 @@
1
+ 1.1.0 - September 7, 2014
2
+ * added a --dry-run cli option
data/README.md CHANGED
@@ -29,6 +29,8 @@ It's that simple. Only one command to run and `chef_attrdoc` will know how to do
29
29
 
30
30
  ### Examples
31
31
 
32
+ These are the two input files from a chef cookbook:
33
+
32
34
  ```bash
33
35
  $ cat cookbook-example/attributes/default.rb
34
36
  ```
@@ -49,10 +51,39 @@ $ cat cookbook-example/attributes/default.rb
49
51
  else
50
52
  default['some']['foo'] = 'qux'
51
53
  end
54
+
55
+ ```bash
56
+ $ cat cookbook-example/README.md
57
+ ```
58
+ chef_attrdoc example README
59
+ ===========================
60
+
61
+ This is just an example
62
+
63
+ Attributes
64
+ ==========
65
+ nothing here now
66
+
67
+
68
+ License
69
+ =======
70
+ This is usually important.
71
+
72
+ This is the output README file after running:
73
+
52
74
  ```bash
53
- $ chef_attrdoc cookbook-example --stdout
75
+ $ chef_attrdoc cookbook-example
76
+ $ cat cookbook-example/README.md
54
77
  ```
55
78
  ```
79
+ chef_attrdoc example README
80
+ ===========================
81
+
82
+ This is just an example
83
+
84
+ Attributes
85
+ ==========
86
+
56
87
  ## default.rb
57
88
 
58
89
  this is the attribute
@@ -72,6 +103,12 @@ $ chef_attrdoc cookbook-example --stdout
72
103
  end
73
104
  ```
74
105
 
106
+
107
+ License
108
+ =======
109
+ This is usually important.
110
+ ```
111
+
75
112
  Here are some longer examples from openstack chef cookbooks:
76
113
 
77
114
  [openstack-identity attributes file](https://github.com/stackforge/cookbook-openstack-identity/blob/552488824aa720f08249bc4d19f5224e9382aa00/attributes/default.rb) - [output](https://gist.github.com/mapleoin/d211b29f68dd519a4878#attributes)
@@ -36,10 +36,17 @@ opt_parser = OptionParser.new do |opts|
36
36
  end
37
37
 
38
38
  opts.on("-s", "--stdout",
39
- "Write output to stdout instead of the cookbook's README file") do |stdout|
39
+ "Write the attributes section to stdout instead of overwriting anything"
40
+ ) do |stdout|
40
41
  options[:stdout] = stdout
41
42
  end
42
43
 
44
+ opts.on("--dry-run",
45
+ "Output the changed README.md to stdout instead of overwriting anything"
46
+ ) do |dry_run|
47
+ options[:dry_run] = dry_run
48
+ end
49
+
43
50
  opts.on_tail("-d", "--debug", "Show tracebacks on errors") do |debug|
44
51
  options[:debug] = debug
45
52
  end
@@ -62,6 +69,8 @@ begin
62
69
  attrs = ChefAttrdoc.process_attributes dir_path
63
70
  if options[:stdout]
64
71
  puts attrs
72
+ elsif options[:dry_run]
73
+ puts ChefAttrdoc.write_readme options[:readme], attrs, true
65
74
  else
66
75
  ChefAttrdoc.write_readme options[:readme], attrs
67
76
  end
@@ -133,8 +133,9 @@ module ChefAttrdoc
133
133
  end
134
134
 
135
135
  # open the :readme: Markdown file and replace the 'Attributes' section
136
- # with the contents of :parsed:
137
- def self.write_readme(readme, parsed)
136
+ # with the contents of :parsed: . If :dry_run: is `true`, the string
137
+ # will be returned instead of overwriting the :readme: file.
138
+ def self.write_readme(readme, parsed, dry_run=false)
138
139
  File.open(readme, File::RDWR) do |f|
139
140
  # TODO find a cleaner way and do this in one step
140
141
  content = f.read
@@ -156,10 +157,14 @@ module ChefAttrdoc
156
157
  # parts of the original README
157
158
  "\n" + parsed.gsub(/\\/, "\\\\\\"))
158
159
 
159
- f.rewind
160
- f.write(updated)
161
- f.flush
162
- f.truncate(f.pos)
160
+ if dry_run
161
+ return updated
162
+ else
163
+ f.rewind
164
+ f.write(updated)
165
+ f.flush
166
+ f.truncate(f.pos)
167
+ end
163
168
  end
164
169
  end
165
170
 
@@ -1,3 +1,3 @@
1
1
  module ChefAttrdoc
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,133 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Copyright 2014, Ionuț Arțăriși <ionut@artarisi.eu>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef_attrdoc'
19
+
20
+ describe 'This is the example from chef_attrdoc\'s README.md' do
21
+ it 'prints the right attributes section when used with --stdout' do
22
+ output = `ruby -Ilib bin/chef_attrdoc spec/fixtures/cookbook-example/ -s`
23
+ expect(output).to eq(<<-OUTPUT)
24
+ ## default.rb
25
+
26
+ this is the attribute
27
+
28
+ ```ruby
29
+ default['some']['attribute'] = 'foo'
30
+ ```
31
+
32
+ a longer block of code
33
+
34
+ ```ruby
35
+ case something
36
+ when 'foo'
37
+ default['some']['foo'] = 'baz'
38
+ else
39
+ default['some']['foo'] = 'qux'
40
+ end
41
+ ```
42
+
43
+ OUTPUT
44
+ end
45
+
46
+ it 'prints the right output when used with --dry-run' do
47
+ output = `ruby -Ilib bin/chef_attrdoc spec/fixtures/cookbook-example/ --dry-run`
48
+ expect(output).to eq(<<-OUTPUT)
49
+ chef_attrdoc example README
50
+ ===========================
51
+
52
+ This is just an example
53
+
54
+ Attributes
55
+ ==========
56
+
57
+ ## default.rb
58
+
59
+ this is the attribute
60
+
61
+ ```ruby
62
+ default['some']['attribute'] = 'foo'
63
+ ```
64
+
65
+ a longer block of code
66
+
67
+ ```ruby
68
+ case something
69
+ when 'foo'
70
+ default['some']['foo'] = 'baz'
71
+ else
72
+ default['some']['foo'] = 'qux'
73
+ end
74
+ ```
75
+
76
+
77
+ License
78
+ =======
79
+ This is usually important.
80
+ OUTPUT
81
+ end
82
+
83
+ describe 'tests which change the README.md fixture' do
84
+ let(:readme) { 'spec/fixtures/cookbook-example/README.md' }
85
+ before do
86
+ @backup = File.read(readme)
87
+ end
88
+
89
+ after do
90
+ File.open(readme, 'w') do |f|
91
+ f.write(@backup)
92
+ end
93
+ end
94
+
95
+ it 'changes the README file appropriately when invoked with no args' do
96
+ output = `ruby -Ilib bin/chef_attrdoc spec/fixtures/cookbook-example/`
97
+ expect(output).to be_empty
98
+ expect(File.read('spec/fixtures/cookbook-example/README.md')).to eq(<<-OUT)
99
+ chef_attrdoc example README
100
+ ===========================
101
+
102
+ This is just an example
103
+
104
+ Attributes
105
+ ==========
106
+
107
+ ## default.rb
108
+
109
+ this is the attribute
110
+
111
+ ```ruby
112
+ default['some']['attribute'] = 'foo'
113
+ ```
114
+
115
+ a longer block of code
116
+
117
+ ```ruby
118
+ case something
119
+ when 'foo'
120
+ default['some']['foo'] = 'baz'
121
+ else
122
+ default['some']['foo'] = 'qux'
123
+ end
124
+ ```
125
+
126
+
127
+ License
128
+ =======
129
+ This is usually important.
130
+ OUT
131
+ end
132
+ end
133
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef_attrdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-06 00:00:00.000000000 Z
12
+ date: 2014-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -54,6 +54,7 @@ files:
54
54
  - .gitignore
55
55
  - .rspec
56
56
  - .travis.yml
57
+ - ChangeLog
57
58
  - Gemfile
58
59
  - LICENSE
59
60
  - README.md
@@ -64,13 +65,13 @@ files:
64
65
  - lib/chef_attrdoc/version.rb
65
66
  - spec/attributes_file_spec.rb
66
67
  - spec/chef_attrdoc_spec.rb
67
- - spec/cli_spec.rb
68
68
  - spec/fixtures/cookbook-example/README.md
69
69
  - spec/fixtures/cookbook-example/attributes/default.rb
70
70
  - spec/fixtures/file1.rb
71
71
  - spec/fixtures/file2
72
72
  - spec/fixtures/file3.rb
73
- - spec/readme_example_spec.rb
73
+ - spec/functional/cli_spec.rb
74
+ - spec/functional/readme_example_spec.rb
74
75
  - spec/spec_helper.rb
75
76
  homepage: https://github.com/mapleoin/chef_attrdoc
76
77
  licenses:
@@ -100,12 +101,12 @@ summary: Generate README.md docs from Chef cookbook attributes files
100
101
  test_files:
101
102
  - spec/attributes_file_spec.rb
102
103
  - spec/chef_attrdoc_spec.rb
103
- - spec/cli_spec.rb
104
104
  - spec/fixtures/cookbook-example/README.md
105
105
  - spec/fixtures/cookbook-example/attributes/default.rb
106
106
  - spec/fixtures/file1.rb
107
107
  - spec/fixtures/file2
108
108
  - spec/fixtures/file3.rb
109
- - spec/readme_example_spec.rb
109
+ - spec/functional/cli_spec.rb
110
+ - spec/functional/readme_example_spec.rb
110
111
  - spec/spec_helper.rb
111
112
  has_rdoc:
@@ -1,45 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # Copyright 2014, Ionuț Arțăriși <ionut@artarisi.eu>
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require 'chef_attrdoc'
19
-
20
- describe 'This is the example from chef_attrdoc\'s README.md' do
21
- it 'has the a fixed output' do
22
- output = `ruby -Ilib bin/chef_attrdoc spec/fixtures/cookbook-example/ -s`
23
- expect(output).to eq(<<-OUTPUT)
24
- ## default.rb
25
-
26
- this is the attribute
27
-
28
- ```ruby
29
- default['some']['attribute'] = 'foo'
30
- ```
31
-
32
- a longer block of code
33
-
34
- ```ruby
35
- case something
36
- when 'foo'
37
- default['some']['foo'] = 'baz'
38
- else
39
- default['some']['foo'] = 'qux'
40
- end
41
- ```
42
-
43
- OUTPUT
44
- end
45
- end