Skip to content

Commit c49ccba

Browse files
committed
feat: introduce --read-paths to threat PATH as a file containing manifest paths
1 parent b44f264 commit c49ccba

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

lib/puppet-lint/bin.rb

+17-8
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,23 @@ def run
6565
full_base_path_uri += '/' unless full_base_path_uri.end_with?('/')
6666

6767
path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
68-
path = if File.directory?(path)
69-
Dir.glob([
70-
"#{path}/**/*.pp",
71-
"#{path}/**/*.{yaml,yml}",
72-
])
73-
else
74-
@args
75-
end
68+
69+
if PuppetLint.configuration.read_paths
70+
paths_from_path = []
71+
File.readlines(path, chomp: true).each do |line|
72+
paths_from_path.append(line)
73+
end
74+
path = paths_from_path
75+
else
76+
path = if File.directory?(path)
77+
Dir.glob([
78+
"#{path}/**/*.pp",
79+
"#{path}/**/*.{yaml,yml}",
80+
])
81+
else
82+
@args
83+
end
84+
end
7685

7786
PuppetLint.configuration.with_filename = true if path.length > 1
7887

lib/puppet-lint/configuration.rb

+1
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,6 @@ def defaults
154154
self.ignore_paths = ['vendor/**/*.pp']
155155
self.github_actions = ENV.key?('GITHUB_ACTION')
156156
self.codeclimate_report_file = ENV.fetch('CODECLIMATE_REPORT_FILE', nil)
157+
self.read_paths = false
157158
end
158159
end

lib/puppet-lint/optparser.rb

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def self.build(args = [])
132132
PuppetLint.configuration.top_scope_variables = vars.split(',')
133133
end
134134

135+
opts.on('--read-paths', 'Threat PATH as a file containing puppet manifest paths.') do
136+
PuppetLint.configuration.read_paths = true
137+
end
138+
135139
PuppetLint.configuration.checks.each do |check|
136140
opts.on("--no-#{check}-check", "Skip the #{check} check.") do
137141
PuppetLint.configuration.send(:"disable_#{check}")

spec/acceptance/puppet_lint_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
result = puppet_lint([File.join(manifest_root, 'two_warnings.pp')])
4343
expect(result[:stdout]).to have_warnings(2)
4444
end
45+
46+
it 'reads paths from file' do
47+
result = puppet_lint(['--read-paths', File.join(manifest_root, 'list')])
48+
expect(result[:stdout]).to have_warnings(1)
49+
expect(result[:stdout]).to have_errors(1)
50+
end
4551
end
4652

4753
context 'with a YAML file provided' do

0 commit comments

Comments
 (0)