From a17bc283d9ee096ea3d9a7d2d8e7bf5e9cf4e49c Mon Sep 17 00:00:00 2001 From: JP Simard Date: Sat, 5 Dec 2015 19:44:45 -0800 Subject: [PATCH] move scriptInputFiles() to Configuration+CommandLine.swift --- Source/swiftlint/Commands/LintCommand.swift | 37 ------------------ .../Configuration+CommandLine.swift | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/Source/swiftlint/Commands/LintCommand.swift b/Source/swiftlint/Commands/LintCommand.swift index fa1cadae5..5c00fb25d 100644 --- a/Source/swiftlint/Commands/LintCommand.swift +++ b/Source/swiftlint/Commands/LintCommand.swift @@ -99,43 +99,6 @@ struct LintCommand: CommandType { } return .Failure(CommandantError<()>.CommandError()) } - - private func scriptInputFiles() -> Result<[String], CommandantError<()>> { - func getEnvironmentVariable(variable: String) -> Result> { - 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> = 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.. 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 { diff --git a/Source/swiftlint/Extensions/Configuration+CommandLine.swift b/Source/swiftlint/Extensions/Configuration+CommandLine.swift index 227186a80..d856c6b76 100644 --- a/Source/swiftlint/Extensions/Configuration+CommandLine.swift +++ b/Source/swiftlint/Extensions/Configuration+CommandLine.swift @@ -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> { + 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> = { + 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.. 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() {