knife-foodcritic 0.1.1
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/knife-foodcritic.gemspec +24 -0
- data/lib/chef/knife/create_foodcritic_rule.rb +112 -0
- data/lib/knife-foodcritic/version.rb +3 -0
- metadata +112 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Edmund Dipple
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'knife-foodcritic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "knife-foodcritic"
|
8
|
+
spec.version = KnifeFoodcritic::VERSION
|
9
|
+
spec.authors = ["Edmund Dipple"]
|
10
|
+
spec.email = ["elmundio1987@gmail.com"]
|
11
|
+
spec.homepage = "http://www.devopsninjas.com"
|
12
|
+
spec.license = "GPL"
|
13
|
+
spec.summary = "A knife plugin for Chef that generates boiler plate code to help develop and test custom foodcritic rules"
|
14
|
+
spec.description = "Knife-Foodcritic is a plugin for Chef::Knife which automatically generates a new rule file (with an optional description), example spec files and a cookbook to test the rule against. It also generates the spec_helper if it doesn't already exist."
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_dependency "chef"
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'chef/knife/cookbook_create'
|
3
|
+
|
4
|
+
module Foodcritic
|
5
|
+
class FoodcriticRuleCreate < Chef::Knife
|
6
|
+
|
7
|
+
banner "knife foodcritic rule create"
|
8
|
+
|
9
|
+
option :foodcritic_desc,
|
10
|
+
:short => '-r VALUE',
|
11
|
+
:long => '--description VALUE',
|
12
|
+
:default => "A very nice rule",
|
13
|
+
:description => "What the rule is checking for"
|
14
|
+
|
15
|
+
|
16
|
+
def run
|
17
|
+
|
18
|
+
unless name_args.size == 1
|
19
|
+
puts "You need to name the rule (eg. FOURTH004)"
|
20
|
+
show_usage
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
foodcritic_path = File.expand_path("./foodcritic")
|
25
|
+
ruleID = name_args.first
|
26
|
+
ruleDesc = config[:foodcritic_desc]
|
27
|
+
|
28
|
+
create_foodcritic_rule(foodcritic_path, ruleID, ruleDesc)
|
29
|
+
create_specs(foodcritic_path, ruleID)
|
30
|
+
create_cookbook(foodcritic_path, ruleID)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_foodcritic_rule(foodcritic_path, ruleID, ruleDesc)
|
35
|
+
|
36
|
+
rule = File.join(foodcritic_path, "lib","Fourth", "#{ruleID.upcase}.rb")
|
37
|
+
|
38
|
+
unless File.exists?(rule)
|
39
|
+
|
40
|
+
puts "** Creating #{ruleID} at #{rule}"
|
41
|
+
|
42
|
+
File.open(rule, 'w') do |file|
|
43
|
+
file.write <<-EOH
|
44
|
+
rule "#{ruleID.upcase}", '#{ruleDesc}' do
|
45
|
+
tags %w{}
|
46
|
+
recipe do |ast,filename|
|
47
|
+
#Your rule logic here
|
48
|
+
end
|
49
|
+
end
|
50
|
+
EOH
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_cookbook(foodcritic_path, ruleID)
|
56
|
+
|
57
|
+
cookbook_folder = File.join(foodcritic_path, "cookbooks" )
|
58
|
+
puts "** Cookbooks directory: #{cookbook_folder}"
|
59
|
+
a = Chef::Knife::CookbookCreate.new
|
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
|
+
|
64
|
+
valid_recipe = File.join(foodcritic_path, "cookbooks", ruleID.downcase, "recipes", "valid.rb")
|
65
|
+
|
66
|
+
unless File.exists?(valid_recipe)
|
67
|
+
File.open(valid_recipe, 'w') do |file|
|
68
|
+
file.write <<-EOH
|
69
|
+
#
|
70
|
+
# Cookbook Name:: #{ruleID.downcase}
|
71
|
+
# Recipe:: valid
|
72
|
+
#
|
73
|
+
# Copyright #{Time.now.year}
|
74
|
+
#
|
75
|
+
EOH
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_specs(foodcritic_path, ruleID)
|
82
|
+
|
83
|
+
spec = File.join(foodcritic_path, "spec","rules", "#{ruleID.upcase}_spec.rb")
|
84
|
+
|
85
|
+
puts "** Creating spec file at #{spec}"
|
86
|
+
|
87
|
+
unless File.exists?(spec)
|
88
|
+
File.open(spec, 'w') do |file|
|
89
|
+
file.write <<-EOH
|
90
|
+
require_relative '../spec_helper'
|
91
|
+
|
92
|
+
RSpec.describe :#{ruleID.upcase} do
|
93
|
+
let(:fc_run) do
|
94
|
+
foodcritic_run('#{ruleID.upcase}')
|
95
|
+
end
|
96
|
+
|
97
|
+
it "generates a warning against the default recipe" do
|
98
|
+
expect(warnings(fc_run)).to include('default.rb')
|
99
|
+
end
|
100
|
+
|
101
|
+
it "does not generate a warning against a valid recipe" do
|
102
|
+
expect(warnings(fc_run)).to_not include('valid.rb')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
EOH
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-foodcritic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Edmund Dipple
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: chef
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Knife-Foodcritic is a plugin for Chef::Knife which automatically generates
|
63
|
+
a new rule file (with an optional description), example spec files and a cookbook
|
64
|
+
to test the rule against. It also generates the spec_helper if it doesn't already
|
65
|
+
exist.
|
66
|
+
email:
|
67
|
+
- elmundio1987@gmail.com
|
68
|
+
executables: []
|
69
|
+
extensions: []
|
70
|
+
extra_rdoc_files: []
|
71
|
+
files:
|
72
|
+
- .gitignore
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- knife-foodcritic.gemspec
|
78
|
+
- lib/chef/knife/create_foodcritic_rule.rb
|
79
|
+
- lib/knife-foodcritic/version.rb
|
80
|
+
homepage: http://www.devopsninjas.com
|
81
|
+
licenses:
|
82
|
+
- GPL
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: 1645001205914449469
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: 1645001205914449469
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.25
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: A knife plugin for Chef that generates boiler plate code to help develop
|
111
|
+
and test custom foodcritic rules
|
112
|
+
test_files: []
|