Files
SwiftLint/Source/swiftlint/Commands/GenerateDocsCommand.swift
T
JP Simard b83e0991b9 Remove all file headers
The MIT license doesn't require that all files be prepended with this
licensing or copyright information. Realm confirmed that they're ok with this
change. This will enable some companies to contribute to SwiftLint and the
date & authorship information will remain accessible via git source control.
2018-05-04 13:42:02 -07:00

40 lines
1.2 KiB
Swift

import Commandant
import Result
import SwiftLintFramework
struct GenerateDocsCommand: CommandProtocol {
let verb = "generate-docs"
let function = "Generates markdown documentation for all rules"
func run(_ options: GenerateDocsOptions) -> Result<(), CommandantError<()>> {
let text = masterRuleList.generateDocumentation()
if let path = options.path {
do {
try text.write(toFile: path, atomically: true, encoding: .utf8)
} catch {
return .failure(.usageError(description: error.localizedDescription))
}
} else {
queuedPrint(text)
}
return .success(())
}
}
struct GenerateDocsOptions: OptionsProtocol {
let path: String?
static func create(_ path: String?) -> GenerateDocsOptions {
return self.init(path: path)
}
static func evaluate(_ mode: CommandMode) -> Result<GenerateDocsOptions, CommandantError<CommandantError<()>>> {
return create
<*> mode <| Option(key: "path", defaultValue: nil,
usage: "the path where the documentation should be saved. " +
"If not present, it'll be printed to the output.")
}
}