knife-foodcritic 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +47 -0
- data/knife-foodcritic.gemspec +1 -0
- data/lib/chef/knife/create_foodcritic_rule.rb +60 -8
- data/lib/chef/knife/delete_foodcritic_rule.rb +53 -0
- data/lib/knife-foodcritic/version.rb +2 -2
- metadata +20 -3
data/README.md
CHANGED
@@ -2,3 +2,50 @@ knife-foodcritic
|
|
2
2
|
================
|
3
3
|
|
4
4
|
A knife plugin that generates boiler plate code for developing and testing custom foodcritic rules
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
### Gem Install
|
10
|
+
`knife-foodcritic` is available on rubygems. Add the following to your `Gemfile`:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'knife-foodcritic'
|
14
|
+
```
|
15
|
+
|
16
|
+
or install the gem manually:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
gem install knife-foodcritic
|
20
|
+
```
|
21
|
+
|
22
|
+
Foodcritic Rule Create
|
23
|
+
----------
|
24
|
+
This function lets you easily create the necessary lib, spec and cookbook files necessary to develop and test a new foodcritic rule.
|
25
|
+
|
26
|
+
#### Usage
|
27
|
+
```bash
|
28
|
+
knife foodcritic rule create ID [ --description DESCRIPTION ]
|
29
|
+
````
|
30
|
+
|
31
|
+
#### Example (Just passing in a rule ID)
|
32
|
+
```text
|
33
|
+
$ knife foodcritic rule create CUSTOM001
|
34
|
+
** Creating Custom001 at /Users/edmundd/Development/lightyear/chef-repo/foodcritic/lib/Fourth/CUSTOM001.rb
|
35
|
+
** Creating spec file at /Users/edmundd/Development/lightyear/chef-repo/foodcritic/spec/rules/CUSTOM001_spec.rb
|
36
|
+
** Cookbooks directory: /Users/edmundd/Development/lightyear/chef-repo/foodcritic/cookbooks
|
37
|
+
** Creating cookbook custom001
|
38
|
+
** Creating metadata for cookbook: custom001
|
39
|
+
** Creating README for cookbook: custom001
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Example (Adding a rule description at creation time)
|
43
|
+
```text
|
44
|
+
$ knife foodcritic rule create CUSTOM001 --description "The best rule in the world"
|
45
|
+
** Creating Custom001 at /Users/edmundd/Development/lightyear/chef-repo/foodcritic/lib/Fourth/CUSTOM001.rb
|
46
|
+
** Creating spec file at /Users/edmundd/Development/lightyear/chef-repo/foodcritic/spec/rules/CUSTOM001_spec.rb
|
47
|
+
** Cookbooks directory: /Users/edmundd/Development/lightyear/chef-repo/foodcritic/cookbooks
|
48
|
+
** Creating cookbook custom001
|
49
|
+
** Creating metadata for cookbook: custom001
|
50
|
+
** Creating README for cookbook: custom001
|
51
|
+
```
|
data/knife-foodcritic.gemspec
CHANGED
@@ -28,15 +28,18 @@ module Foodcritic
|
|
28
28
|
create_foodcritic_rule(foodcritic_path, ruleID, ruleDesc)
|
29
29
|
create_specs(foodcritic_path, ruleID)
|
30
30
|
create_cookbook(foodcritic_path, ruleID)
|
31
|
+
create_spec_helper(foodcritic_path)
|
31
32
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def create_foodcritic_rule(foodcritic_path, ruleID, ruleDesc)
|
35
36
|
|
36
|
-
rule = File.join(foodcritic_path, "
|
37
|
+
rule = File.join(foodcritic_path, "rules", "#{ruleID.upcase}.rb")
|
37
38
|
|
38
39
|
unless File.exists?(rule)
|
39
40
|
|
41
|
+
FileUtils.mkdir_p File.dirname(rule)
|
42
|
+
|
40
43
|
puts "** Creating #{ruleID} at #{rule}"
|
41
44
|
|
42
45
|
File.open(rule, 'w') do |file|
|
@@ -55,15 +58,21 @@ end
|
|
55
58
|
def create_cookbook(foodcritic_path, ruleID)
|
56
59
|
|
57
60
|
cookbook_folder = File.join(foodcritic_path, "cookbooks" )
|
58
|
-
|
59
|
-
|
60
|
-
a.create_cookbook(cookbook_folder, ruleID.downcase, Chef::Config[:cookbook_copyright] , Chef::Config[:cookbook_license])
|
61
|
-
a.create_metadata(cookbook_folder, ruleID.downcase, Chef::Config[:cookbook_copyright], Chef::Config[:cookbook_email], Chef::Config[:cookbook_license], "md")
|
62
|
-
a.create_readme(cookbook_folder, ruleID.downcase, "md")
|
63
|
-
|
61
|
+
|
62
|
+
|
64
63
|
valid_recipe = File.join(foodcritic_path, "cookbooks", ruleID.downcase, "recipes", "valid.rb")
|
65
64
|
|
66
65
|
unless File.exists?(valid_recipe)
|
66
|
+
|
67
|
+
puts "** Cookbooks directory: #{cookbook_folder}"
|
68
|
+
|
69
|
+
FileUtils.mkdir_p File.dirname(cookbook_folder)
|
70
|
+
|
71
|
+
a = Chef::Knife::CookbookCreate.new
|
72
|
+
a.create_cookbook(cookbook_folder, ruleID.downcase, Chef::Config[:cookbook_copyright] , Chef::Config[:cookbook_license])
|
73
|
+
a.create_metadata(cookbook_folder, ruleID.downcase, Chef::Config[:cookbook_copyright], Chef::Config[:cookbook_email], Chef::Config[:cookbook_license], "md")
|
74
|
+
a.create_readme(cookbook_folder, ruleID.downcase, "md")
|
75
|
+
|
67
76
|
File.open(valid_recipe, 'w') do |file|
|
68
77
|
file.write <<-EOH
|
69
78
|
#
|
@@ -82,9 +91,14 @@ EOH
|
|
82
91
|
|
83
92
|
spec = File.join(foodcritic_path, "spec","rules", "#{ruleID.upcase}_spec.rb")
|
84
93
|
|
85
|
-
|
94
|
+
|
86
95
|
|
87
96
|
unless File.exists?(spec)
|
97
|
+
|
98
|
+
puts "** Creating spec file at #{spec}"
|
99
|
+
|
100
|
+
FileUtils.mkdir_p File.dirname(spec)
|
101
|
+
|
88
102
|
File.open(spec, 'w') do |file|
|
89
103
|
file.write <<-EOH
|
90
104
|
require_relative '../spec_helper'
|
@@ -108,5 +122,43 @@ end
|
|
108
122
|
|
109
123
|
end
|
110
124
|
|
125
|
+
def create_spec_helper(foodcritic_path)
|
126
|
+
|
127
|
+
spec = File.join(foodcritic_path, "spec","spec_helper.rb")
|
128
|
+
|
129
|
+
unless File.exists?(spec)
|
130
|
+
|
131
|
+
puts "** Creating spec helper file at #{spec}"
|
132
|
+
|
133
|
+
File.open(spec, 'w') do |file|
|
134
|
+
|
135
|
+
file.write %q{require 'rspec'
|
136
|
+
require 'foodcritic'
|
137
|
+
|
138
|
+
PROJECT_ROOT = File.expand_path(File.dirname(__FILE__))
|
139
|
+
|
140
|
+
def foodcritic_run(ruleid)
|
141
|
+
fc = FoodCritic::Linter.new
|
142
|
+
|
143
|
+
cb_path = File.join(PROJECT_ROOT, '..' , 'cookbooks', ruleid.downcase)
|
144
|
+
|
145
|
+
opts = {
|
146
|
+
:cookbook_paths => cb_path,
|
147
|
+
:include_rules => File.join(PROJECT_ROOT,'..','rules',"#{ruleid}.rb"),
|
148
|
+
:tags => [ruleid.upcase]
|
149
|
+
}
|
150
|
+
|
151
|
+
fc.check(opts)
|
152
|
+
end
|
153
|
+
|
154
|
+
def warnings(fc_run)
|
155
|
+
fc_run.warnings.collect { |w| File.basename(w.match[:filename]) }.uniq
|
156
|
+
end
|
157
|
+
}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
111
163
|
end
|
112
164
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module Foodcritic
|
4
|
+
class FoodcriticRuleDelete < Chef::Knife
|
5
|
+
|
6
|
+
banner "knife foodcritic rule delete"
|
7
|
+
|
8
|
+
def run
|
9
|
+
|
10
|
+
foodcritic_path = File.expand_path("./foodcritic")
|
11
|
+
ruleID = name_args.first
|
12
|
+
|
13
|
+
delete_foodcritic_rule(foodcritic_path, ruleID)
|
14
|
+
delete_specs(foodcritic_path, ruleID)
|
15
|
+
delete_cookbook(foodcritic_path, ruleID)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete_foodcritic_rule(foodcritic_path, ruleID)
|
20
|
+
path = File.join(foodcritic_path, "lib","Fourth", "#{ruleID.upcase}.rb")
|
21
|
+
|
22
|
+
if File.exists? path
|
23
|
+
puts "** Deleting rule file at #{path}"
|
24
|
+
FileUtils.rm path
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_cookbook(foodcritic_path, ruleID)
|
30
|
+
|
31
|
+
path = File.join(foodcritic_path, "cookbooks", ruleID)
|
32
|
+
|
33
|
+
if File.exists? path
|
34
|
+
puts "** Deleting cookbook at #{path}"
|
35
|
+
FileUtils.rm_rf path
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_specs(foodcritic_path, ruleID)
|
41
|
+
|
42
|
+
|
43
|
+
path = File.join(foodcritic_path, "spec","rules", "#{ruleID.upcase}_spec.rb")
|
44
|
+
|
45
|
+
if File.exists? path
|
46
|
+
puts "** Deleting spec file at #{path}"
|
47
|
+
FileUtils.rm path
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module KnifeFoodcritic
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.2.0"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-foodcritic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: foodcritic
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.0.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 4.0.0
|
62
78
|
description: Knife-Foodcritic is a plugin for Chef::Knife which automatically generates
|
63
79
|
a new rule file (with an optional description), example spec files and a cookbook
|
64
80
|
to test the rule against. It also generates the spec_helper if it doesn't already
|
@@ -76,6 +92,7 @@ files:
|
|
76
92
|
- Rakefile
|
77
93
|
- knife-foodcritic.gemspec
|
78
94
|
- lib/chef/knife/create_foodcritic_rule.rb
|
95
|
+
- lib/chef/knife/delete_foodcritic_rule.rb
|
79
96
|
- lib/knife-foodcritic/version.rb
|
80
97
|
homepage: http://www.devopsninjas.com
|
81
98
|
licenses:
|
@@ -92,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
109
|
version: '0'
|
93
110
|
segments:
|
94
111
|
- 0
|
95
|
-
hash:
|
112
|
+
hash: 3583670318698646123
|
96
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
114
|
none: false
|
98
115
|
requirements:
|
@@ -101,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
118
|
version: '0'
|
102
119
|
segments:
|
103
120
|
- 0
|
104
|
-
hash:
|
121
|
+
hash: 3583670318698646123
|
105
122
|
requirements: []
|
106
123
|
rubyforge_project:
|
107
124
|
rubygems_version: 1.8.25
|