license_header 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/license_header +7 -3
- data/lib/license_header/auditor.rb +15 -13
- data/lib/license_header/version.rb +1 -1
- metadata +3 -8
data/bin/license_header
CHANGED
@@ -64,14 +64,14 @@ opts = OptionParser.new do |opts|
|
|
64
64
|
|
65
65
|
opts.on_tail('-h', '--help', "Show this message") do
|
66
66
|
puts opts
|
67
|
-
exit
|
67
|
+
exit 1
|
68
68
|
end
|
69
69
|
end
|
70
70
|
opts.parse!
|
71
71
|
|
72
|
-
if command.nil? or
|
72
|
+
if command.nil? or ARGV.empty?
|
73
73
|
puts opts
|
74
|
-
exit
|
74
|
+
exit 1
|
75
75
|
end
|
76
76
|
|
77
77
|
targets = ARGV.collect do |spec|
|
@@ -91,6 +91,10 @@ when :audit
|
|
91
91
|
$stderr.puts "#{files[:invalid].length} files have invalid headers"
|
92
92
|
$stderr.puts files[:invalid].join("\n") if options[:verbose]
|
93
93
|
when :update
|
94
|
+
if options[:header].nil?
|
95
|
+
put opts
|
96
|
+
exit 1
|
97
|
+
end
|
94
98
|
$stderr.puts "#{invalid.length} files have missing or incorrect headers"
|
95
99
|
auditor.process_files(:update, * invalid) do |file, format|
|
96
100
|
response = getYyn("Update header in #{file}?")
|
@@ -4,21 +4,23 @@ require 'fileutils'
|
|
4
4
|
# block as a header.
|
5
5
|
|
6
6
|
module LicenseHeader
|
7
|
-
# For each language you can define
|
7
|
+
# For each language you can define five variables
|
8
8
|
#
|
9
9
|
# :pre will be prepended to the header
|
10
10
|
# :each will be prepended to each line of the header
|
11
11
|
# :post will be appended to the end of the file
|
12
|
+
# :sep determines whether an empty line should separate the header from the body
|
13
|
+
# :exts lists the extensions the syntax will apply to
|
12
14
|
#
|
13
15
|
# Only :each is required; if the other two are not provided they will be
|
14
16
|
# ignored
|
15
17
|
LANGUAGE_SYNTAX = {
|
16
|
-
:css => { :pre => '/* ', :each => ' * ', :post => '*/', :exts => %w(.css .scss) },
|
17
|
-
:erb => { :pre => '<%#', :each => '', :post => '%>', :exts => %w(.erb) },
|
18
|
-
:haml => { :pre => '-#', :each => ' ', :exts => %w(.haml) },
|
19
|
-
:html => { :pre => '<!--', :each => '', :post => '-->', :exts => %w(.html) },
|
20
|
-
:javascript => { :pre => '/* ', :each => ' * ', :post => '*/', :exts => %w(.js .json) },
|
21
|
-
:ruby => { :each => '# ', :exts => %w(.rb .rake .coffee .pp) },
|
18
|
+
:css => { :pre => '/* ', :each => ' * ', :post => '*/', :sep => true, :exts => %w(.css .scss) },
|
19
|
+
:erb => { :pre => '<%#', :each => '', :post => '%>', :sep => false, :exts => %w(.erb) },
|
20
|
+
:haml => { :pre => '-#', :each => ' ', :sep => true, :exts => %w(.haml) },
|
21
|
+
:html => { :pre => '<!--', :each => '', :post => '-->', :sep => false, :exts => %w(.html) },
|
22
|
+
:javascript => { :pre => '/* ', :each => ' * ', :post => '*/', :sep => true, :exts => %w(.js .json) },
|
23
|
+
:ruby => { :each => '# ', :sep => true, :exts => %w(.rb .rake .coffee .pp) },
|
22
24
|
}
|
23
25
|
|
24
26
|
class Auditor
|
@@ -96,8 +98,9 @@ module LicenseHeader
|
|
96
98
|
if end_of_license.nil?
|
97
99
|
return false
|
98
100
|
else
|
99
|
-
|
100
|
-
|
101
|
+
end_of_license += 1 if format[:post]
|
102
|
+
end_of_license += 1 if format[:sep]
|
103
|
+
source_file.shift(end_of_license+1)
|
101
104
|
return true
|
102
105
|
end
|
103
106
|
end
|
@@ -123,19 +126,18 @@ module LicenseHeader
|
|
123
126
|
# Javascript that uses /* */ syntax
|
124
127
|
def initialize_headers
|
125
128
|
@headers = LANGUAGE_SYNTAX.clone
|
126
|
-
base = File.read(@header)
|
129
|
+
base = File.read(@header) rescue nil
|
127
130
|
# Break each line down so we can do easy manipulation to create our new
|
128
131
|
# versions
|
129
|
-
license_terms = base.split(/\n/)
|
132
|
+
license_terms = base.nil? ? [] : base.split(/\n/)
|
130
133
|
|
131
134
|
@headers.each_pair do |lang,syntax|
|
132
135
|
syntax[:header] = []
|
133
136
|
syntax[:header] << syntax[:pre] unless syntax[:pre].nil?
|
134
|
-
syntax[:header] << "#{syntax[:each]}--- BEGIN LICENSE_HEADER BLOCK ---"
|
135
137
|
syntax[:header] += license_terms.collect {|line| syntax[:each] + line }
|
136
138
|
syntax[:header] << "#{syntax[:each]}--- #{'E'}ND LICENSE_HEADER BLOCK ---"
|
137
139
|
syntax[:header] << syntax[:post] unless syntax[:post].nil?
|
138
|
-
syntax[:header] << ""
|
140
|
+
syntax[:header] << "" if syntax[:sep]
|
139
141
|
end
|
140
142
|
end
|
141
143
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: license_header
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-04-
|
14
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: highline
|
@@ -86,18 +86,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- - ! '>='
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
|
-
segments:
|
90
|
-
- 0
|
91
|
-
hash: 3490609554518163732
|
92
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
90
|
none: false
|
94
91
|
requirements:
|
95
92
|
- - ! '>='
|
96
93
|
- !ruby/object:Gem::Version
|
97
94
|
version: '0'
|
98
|
-
segments:
|
99
|
-
- 0
|
100
|
-
hash: 3490609554518163732
|
101
95
|
requirements: []
|
102
96
|
rubyforge_project:
|
103
97
|
rubygems_version: 1.8.23
|
@@ -106,3 +100,4 @@ specification_version: 3
|
|
106
100
|
summary: This gem will assist in making sure that all files have the right license
|
107
101
|
block as a header.
|
108
102
|
test_files: []
|
103
|
+
has_rdoc:
|