Add support for params files for file path arguments

This allows you to pass `@path/to/file` which will be read line by line
for the list of files to lint / analyze. This is useful if you want to
pass a massive list of files which will either exceed arg max, or
break most unix tools if you use script input files + env vars.
This commit is contained in:
Keith Smiley
2020-08-20 11:20:09 -07:00
parent e90d2e2005
commit 32579f457a
2 changed files with 14 additions and 3 deletions
+2 -1
View File
@@ -10,7 +10,8 @@
#### Enhancements
* None.
* Add support for params files for file paths.
[keith](https://github.com/keith)
#### Bug Fixes
@@ -28,6 +28,16 @@ enum LintOrAnalyzeModeWithCompilerArguments {
case analyze(allCompilerInvocations: CompilerInvocations)
}
private func resolveParamsFiles(args: [String]) -> [String] {
return args.reduce(into: []) { allArgs, arg in
if arg.hasPrefix("@"), let contents = try? String(contentsOfFile: String(arg.dropFirst())) {
allArgs += resolveParamsFiles(args: contents.split(separator: "\n").map(String.init))
} else if !arg.isEmpty {
allArgs.append(arg)
}
}
}
struct LintableFilesVisitor {
let paths: [String]
let action: String
@@ -44,7 +54,7 @@ struct LintableFilesVisitor {
init(paths: [String], action: String, useSTDIN: Bool, quiet: Bool, useScriptInputFiles: Bool, forceExclude: Bool,
cache: LinterCache?, parallel: Bool,
allowZeroLintableFiles: Bool, block: @escaping (CollectedLinter) -> Void) {
self.paths = paths
self.paths = resolveParamsFiles(args: paths)
self.action = action
self.useSTDIN = useSTDIN
self.quiet = quiet
@@ -61,7 +71,7 @@ struct LintableFilesVisitor {
useScriptInputFiles: Bool, forceExclude: Bool,
cache: LinterCache?, compilerInvocations: CompilerInvocations?,
allowZeroLintableFiles: Bool, block: @escaping (CollectedLinter) -> Void) {
self.paths = paths
self.paths = resolveParamsFiles(args: paths)
self.action = action
self.useSTDIN = useSTDIN
self.quiet = quiet