knife-cookbook-doc 0.25.2 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE.md +3 -1
- data/.gitignore +2 -0
- data/CHANGELOG.md +20 -0
- data/Rakefile +9 -0
- data/fixture/README-expected.md +19 -0
- data/fixture/libraries/default.rb +7 -0
- data/fixture/resources/space.rb +13 -0
- data/lib/chef/knife/README.md.erb +8 -1
- data/lib/chef/knife/cookbook_doc.rb +1 -0
- data/lib/knife_cookbook_doc/libraries_model.rb +13 -0
- data/lib/knife_cookbook_doc/rake_task.rb +1 -0
- data/lib/knife_cookbook_doc/readme_model.rb +34 -1
- data/lib/knife_cookbook_doc/resource_model.rb +11 -7
- data/lib/knife_cookbook_doc/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d4b4645d7d5c912ee0727e526541469198e048c75792d308624039278329a729
|
4
|
+
data.tar.gz: 60ba6053bb465d1e50cca894de9ff772a6e0ab180b78800c738bd9e67136c142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a31986554dce09246b247c9c50a10d720f8025a02eb059fea3b4d8dc3deb7f64dc10a70488eb37fd2e57d56d7518a2d3516d469682c54d04949912a34a0f2d5d
|
7
|
+
data.tar.gz: f91942855366f6cb84292754909217b881d9292d5e3c3843062aebba7865507b6e3da3a266afb9b73778ff8ede007e4c53b54921cf63db78fd9bdae28f50d20e
|
data/.github/ISSUE_TEMPLATE.md
CHANGED
@@ -35,7 +35,9 @@ Reproduction repository:
|
|
35
35
|
|
36
36
|
<!--
|
37
37
|
If possible, please create a repository that reproduces the issue with the
|
38
|
-
minimal amount of code possible.
|
38
|
+
minimal amount of code possible. It is highly recommended you take the time
|
39
|
+
to read "How to create a Minimal, Complete, and Verifiable example" at
|
40
|
+
https://stackoverflow.com/help/mcve
|
39
41
|
-->
|
40
42
|
|
41
43
|
Problem description:
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# v0.30.0 (Mar 19 2021)
|
2
|
+
|
3
|
+
* Support a space after # in custom resource. Submitted by Tomoya Kabe.
|
4
|
+
|
5
|
+
# v0.29.0 (Jun 26 2020)
|
6
|
+
|
7
|
+
* Extract descriptions from `libraries/*.rb`. Submitted by Joe Nuspl.
|
8
|
+
|
9
|
+
# v0.28.0 (Jun 11 2020)
|
10
|
+
|
11
|
+
* If `Berksfile` exists, add source_url links to cookbooks. Submitted by Joe Nuspl.
|
12
|
+
|
13
|
+
# v0.27.0 (Jun 20 2019)
|
14
|
+
|
15
|
+
* Add support for Chef 15. Submitted by grozan.
|
16
|
+
|
17
|
+
# v0.26.0 (Mar 4 2019)
|
18
|
+
|
19
|
+
* Display `lazy` defaults as such. Submitted by Joe Nuspl.
|
20
|
+
|
1
21
|
# v0.25.2 (Dec 18 2018)
|
2
22
|
|
3
23
|
* Re-release gem with the appropriate version.
|
data/Rakefile
CHANGED
@@ -4,3 +4,12 @@ require 'rake/clean'
|
|
4
4
|
task :default => :build
|
5
5
|
|
6
6
|
CLEAN.include 'pkg'
|
7
|
+
|
8
|
+
task :test => :install
|
9
|
+
task :test do
|
10
|
+
sh <<SCRIPT
|
11
|
+
cd fixture
|
12
|
+
knife cookbook doc . -o README-generated.md -c knife.rb
|
13
|
+
diff -u README-expected.md README-generated.md && rm README-generated.md
|
14
|
+
SCRIPT
|
15
|
+
end
|
data/fixture/README-expected.md
CHANGED
@@ -36,6 +36,7 @@ MyApp Admin Group: The group allowed to manage MyApp.
|
|
36
36
|
# Resources
|
37
37
|
|
38
38
|
* [fixture](#fixture) - This resource is awesome.
|
39
|
+
* [fixture_space](#fixture_space) - This resource is spacial.
|
39
40
|
|
40
41
|
## fixture
|
41
42
|
|
@@ -50,6 +51,24 @@ This resource is awesome.
|
|
50
51
|
- my_attribute: This is an attribute. Defaults to <code>"a default value"</code>.
|
51
52
|
- my_property: This is a property. Defaults to <code>"another default value"</code>.
|
52
53
|
|
54
|
+
## fixture_space
|
55
|
+
|
56
|
+
This resource is spacial.
|
57
|
+
|
58
|
+
### Actions
|
59
|
+
|
60
|
+
- stuff: Inserts spaces. Default action.
|
61
|
+
|
62
|
+
### Attribute Parameters
|
63
|
+
|
64
|
+
- my_attribute: This is an attribute. Defaults to <code>"a default value"</code>.
|
65
|
+
- my_property: This is a property. Defaults to <code>"another default value"</code>.
|
66
|
+
|
67
|
+
# Libraries
|
68
|
+
|
69
|
+
## stooges()
|
70
|
+
Returns `['Moe', 'Larry', 'Curly']`
|
71
|
+
|
53
72
|
# Credits
|
54
73
|
|
55
74
|
* Mathias Lafeldt
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# <
|
2
|
+
# This resource is spacial.
|
3
|
+
#
|
4
|
+
# @action stuff Inserts spaces.
|
5
|
+
# >
|
6
|
+
|
7
|
+
default_action :stuff
|
8
|
+
|
9
|
+
# <> @attribute my_attribute This is an attribute.
|
10
|
+
attribute :my_attribute, default: 'a default value'
|
11
|
+
|
12
|
+
# <> @property my_property This is a property.
|
13
|
+
property :my_property, default: 'another default value'
|
@@ -147,7 +147,7 @@
|
|
147
147
|
### Attribute Parameters
|
148
148
|
|
149
149
|
<% resource.attributes.each do |attribute| -%>
|
150
|
-
- <%= attribute %>: <%= resource.attribute_description(attribute) %><% if resource.attribute_has_default_value?(attribute) %> Defaults to <code><%= resource.attribute_default_value(attribute)
|
150
|
+
- <%= attribute %>: <%= resource.attribute_description(attribute) %><% if resource.attribute_has_default_value?(attribute) %> Defaults to <code><%= resource.attribute_default_value(attribute) %></code>.<% end %>
|
151
151
|
<% end -%>
|
152
152
|
<% end -%>
|
153
153
|
<% resource.top_level_descriptions.keys.select{|k| k != 'main'}.each do |key| -%>
|
@@ -157,6 +157,13 @@
|
|
157
157
|
<%= resource.top_level_description(key) -%>
|
158
158
|
<% end -%>
|
159
159
|
|
160
|
+
<% end -%>
|
161
|
+
<% end -%>
|
162
|
+
<% unless libraries.empty? -%>
|
163
|
+
# Libraries
|
164
|
+
<% libraries.each do |lib| -%>
|
165
|
+
|
166
|
+
<%= lib.descriptions %>
|
160
167
|
<% end -%>
|
161
168
|
<% end -%>
|
162
169
|
<% fragments.keys.select {|k|k != 'overview' && k != 'credit' && k != 'requirements'}.each do |key| -%>
|
@@ -9,6 +9,7 @@ module KnifeCookbookDoc
|
|
9
9
|
require 'knife_cookbook_doc/base_model'
|
10
10
|
require 'knife_cookbook_doc/documenting_lwrp_base'
|
11
11
|
require 'knife_cookbook_doc/definitions_model'
|
12
|
+
require 'knife_cookbook_doc/libraries_model'
|
12
13
|
require 'knife_cookbook_doc/readme_model'
|
13
14
|
require 'knife_cookbook_doc/recipe_model'
|
14
15
|
require 'knife_cookbook_doc/resource_model'
|
@@ -6,6 +6,7 @@ require 'rake/tasklib'
|
|
6
6
|
require 'knife_cookbook_doc/base_model'
|
7
7
|
require 'knife_cookbook_doc/documenting_lwrp_base'
|
8
8
|
require 'knife_cookbook_doc/definitions_model'
|
9
|
+
require 'knife_cookbook_doc/libraries_model'
|
9
10
|
require 'knife_cookbook_doc/readme_model'
|
10
11
|
require 'knife_cookbook_doc/recipe_model'
|
11
12
|
require 'knife_cookbook_doc/resource_model'
|
@@ -1,13 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'berkshelf'
|
3
|
+
rescue LoadError
|
4
|
+
# won't be able to get :source_url for dependent cookbooks
|
5
|
+
end
|
6
|
+
|
1
7
|
module KnifeCookbookDoc
|
2
8
|
class ReadmeModel
|
3
9
|
DEFAULT_CONSTRAINT = ">= 0.0.0".freeze
|
4
10
|
|
11
|
+
attr_reader :libraries
|
12
|
+
|
5
13
|
def initialize(cookbook_dir, config)
|
6
14
|
|
7
15
|
@metadata = Chef::Cookbook::Metadata.new
|
8
16
|
@metadata.from_file("#{cookbook_dir}/metadata.rb")
|
9
17
|
|
10
|
-
if !@metadata.attributes.empty?
|
18
|
+
if (!@metadata.attributes.empty? rescue false)
|
11
19
|
@attributes = @metadata.attributes.map do |attr, options|
|
12
20
|
name = "node['#{attr.gsub("/", "']['")}']"
|
13
21
|
[name, options['description'], options['default'], options['choice']]
|
@@ -22,6 +30,10 @@ module KnifeCookbookDoc
|
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
33
|
+
@libraries = Dir["#{cookbook_dir}/libraries/*.rb"].sort.map do |path|
|
34
|
+
LibrariesModel.new(@metadata.name, path)
|
35
|
+
end
|
36
|
+
|
25
37
|
@resources = []
|
26
38
|
Dir["#{cookbook_dir}/resources/*.rb"].sort.each do |resource_filename|
|
27
39
|
@resources << ResourceModel.new(@metadata.name, resource_filename)
|
@@ -172,7 +184,28 @@ module KnifeCookbookDoc
|
|
172
184
|
|
173
185
|
private
|
174
186
|
|
187
|
+
def source_url_from_berkshelf(name)
|
188
|
+
@source_url ||= begin
|
189
|
+
if File.exist?('Berksfile') && defined?(::Berkshelf)
|
190
|
+
::Berkshelf::Berksfile
|
191
|
+
.from_file('Berksfile')
|
192
|
+
.install
|
193
|
+
.map { |cb| [cb.cookbook_name, cb.metadata.source_url] }
|
194
|
+
.to_h
|
195
|
+
else
|
196
|
+
{}
|
197
|
+
end
|
198
|
+
end
|
199
|
+
@source_url[name]
|
200
|
+
end
|
201
|
+
|
175
202
|
def format_constraint(name, version)
|
203
|
+
url = source_url_from_berkshelf(name)
|
204
|
+
if !url.nil? && url.start_with?('http')
|
205
|
+
# git:// and ssh:// URLs are not browsable
|
206
|
+
name = "[#{name}](#{url})"
|
207
|
+
end
|
208
|
+
|
176
209
|
if @constraints && version != DEFAULT_CONSTRAINT
|
177
210
|
"#{name} (#{version})"
|
178
211
|
else
|
@@ -52,14 +52,18 @@ module KnifeCookbookDoc
|
|
52
52
|
|
53
53
|
def attribute_has_default_value?(attribute)
|
54
54
|
specification = @native_resource.attribute_specifications[attribute]
|
55
|
-
specification && specification.
|
55
|
+
specification && specification.key?(:default)
|
56
56
|
end
|
57
57
|
|
58
58
|
def attribute_default_value(attribute)
|
59
|
-
if attribute_has_default_value?(attribute)
|
60
|
-
|
59
|
+
default = if attribute_has_default_value?(attribute)
|
60
|
+
@native_resource.attribute_specifications[attribute][:default]
|
61
|
+
end
|
62
|
+
|
63
|
+
if default.is_a?(Chef::DelayedEvaluator)
|
64
|
+
'lazy { ... }'
|
61
65
|
else
|
62
|
-
|
66
|
+
default.inspect
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
@@ -94,13 +98,13 @@ module KnifeCookbookDoc
|
|
94
98
|
resource_class.resource_name = filename_to_qualified_string(cookbook_name, filename)
|
95
99
|
resource_class.run_context = nil
|
96
100
|
resource_data = IO.read(filename)
|
97
|
-
resource_data = resource_data.gsub(/^=begin *\n
|
101
|
+
resource_data = resource_data.gsub(/^=begin *\n *\# ?\<\n(.*?)^ *\# ?\>\n=end *\n/m) do
|
98
102
|
"desc <<DOCO\n#{$1}\nDOCO\n"
|
99
103
|
end
|
100
|
-
resource_data = resource_data.gsub(/^
|
104
|
+
resource_data = resource_data.gsub(/^ *\# ?\<\n(.*?)^ *\# ?\>\n/m) do
|
101
105
|
"desc <<DOCO\n#{$1.gsub(/^ *\# ?/, '')}\nDOCO\n"
|
102
106
|
end
|
103
|
-
resource_data = resource_data.gsub(/^
|
107
|
+
resource_data = resource_data.gsub(/^ *\# ?\<\> (.*?)$/) do
|
104
108
|
"desc #{$1.inspect}\n"
|
105
109
|
end
|
106
110
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-cookbook-doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Lafeldt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -94,9 +94,11 @@ files:
|
|
94
94
|
- fixture/doc/overview.md
|
95
95
|
- fixture/gemfile
|
96
96
|
- fixture/knife.rb
|
97
|
+
- fixture/libraries/default.rb
|
97
98
|
- fixture/metadata.rb
|
98
99
|
- fixture/recipes/default.rb
|
99
100
|
- fixture/resources/default.rb
|
101
|
+
- fixture/resources/space.rb
|
100
102
|
- knife_cookbook_doc.gemspec
|
101
103
|
- lib/chef/knife/README.md.erb
|
102
104
|
- lib/chef/knife/cookbook_doc.rb
|
@@ -104,6 +106,7 @@ files:
|
|
104
106
|
- lib/knife_cookbook_doc/base_model.rb
|
105
107
|
- lib/knife_cookbook_doc/definitions_model.rb
|
106
108
|
- lib/knife_cookbook_doc/documenting_lwrp_base.rb
|
109
|
+
- lib/knife_cookbook_doc/libraries_model.rb
|
107
110
|
- lib/knife_cookbook_doc/rake_task.rb
|
108
111
|
- lib/knife_cookbook_doc/readme_model.rb
|
109
112
|
- lib/knife_cookbook_doc/recipe_model.rb
|
@@ -130,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
133
|
- !ruby/object:Gem::Version
|
131
134
|
version: '0'
|
132
135
|
requirements: []
|
133
|
-
|
134
|
-
rubygems_version: 2.5.1
|
136
|
+
rubygems_version: 3.1.4
|
135
137
|
signing_key:
|
136
138
|
specification_version: 4
|
137
139
|
summary: Knife plugin to generate README.md for a cookbook
|