mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
move scriptInputFiles() to Configuration+CommandLine.swift
This commit is contained in:
@@ -99,43 +99,6 @@ struct LintCommand: CommandType {
|
||||
}
|
||||
return .Failure(CommandantError<()>.CommandError())
|
||||
}
|
||||
|
||||
private func scriptInputFiles() -> Result<[String], CommandantError<()>> {
|
||||
func getEnvironmentVariable(variable: String) -> Result<String, CommandantError<()>> {
|
||||
let environment = NSProcessInfo.processInfo().environment
|
||||
if let value = environment[variable] {
|
||||
return .Success(value)
|
||||
} else {
|
||||
return .Failure(.UsageError(description: "Environment variable not set:" +
|
||||
" \(variable)"))
|
||||
}
|
||||
}
|
||||
|
||||
let count: Result<Int, CommandantError<()>> = getEnvironmentVariable(
|
||||
"SCRIPT_INPUT_FILE_COUNT").flatMap { count in
|
||||
if let i = Int(count) {
|
||||
return .Success(i)
|
||||
} else {
|
||||
return .Failure(.UsageError(description: "SCRIPT_INPUT_FILE_COUNT did not specify" +
|
||||
" a number"))
|
||||
}
|
||||
}
|
||||
|
||||
return count.flatMap { count in
|
||||
let variables = (0..<count)
|
||||
.map { getEnvironmentVariable("SCRIPT_INPUT_FILE_\($0)") }
|
||||
.flatMap { path -> String? in
|
||||
switch path {
|
||||
case let .Success(path):
|
||||
return path
|
||||
case let .Failure(error):
|
||||
queuedPrintError(String(error))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return Result(variables)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LintOptions: OptionsType {
|
||||
|
||||
@@ -6,10 +6,49 @@
|
||||
// Copyright © 2015 Realm. All rights reserved.
|
||||
//
|
||||
|
||||
import Commandant
|
||||
import Foundation
|
||||
import Result
|
||||
import SourceKittenFramework
|
||||
import SwiftLintFramework
|
||||
|
||||
private let inputFileKey = "SCRIPT_INPUT_FILE_COUNT"
|
||||
|
||||
func scriptInputFiles() -> Result<[String], CommandantError<()>> {
|
||||
func getEnvironmentVariable(variable: String) -> Result<String, CommandantError<()>> {
|
||||
let environment = NSProcessInfo.processInfo().environment
|
||||
if let value = environment[variable] {
|
||||
return .Success(value)
|
||||
}
|
||||
return .Failure(.UsageError(description: "Environment variable not set: \(variable)"))
|
||||
}
|
||||
|
||||
let count: Result<Int, CommandantError<()>> = {
|
||||
guard let countString = NSProcessInfo.processInfo().environment[inputFileKey] else {
|
||||
return .Failure(.UsageError(description: "\(inputFileKey) variable not set"))
|
||||
}
|
||||
if let count = Int(countString) {
|
||||
return .Success(count)
|
||||
}
|
||||
return .Failure(.UsageError(description: "\(inputFileKey) did not specify a number"))
|
||||
}()
|
||||
|
||||
return count.flatMap { count in
|
||||
let inputFiles = (0..<count)
|
||||
.map { getEnvironmentVariable("SCRIPT_INPUT_FILE_\($0)") }
|
||||
.flatMap { path -> String? in
|
||||
switch path {
|
||||
case let .Success(path):
|
||||
return path
|
||||
case let .Failure(error):
|
||||
queuedPrintError(String(error))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return Result(inputFiles)
|
||||
}
|
||||
}
|
||||
|
||||
extension File {
|
||||
private static func maybeSwiftFile(path: String) -> File? {
|
||||
if let file = File(path: path) where path.isSwiftFile() {
|
||||
|
||||
Reference in New Issue
Block a user