mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
b83e0991b9
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.
40 lines
1.2 KiB
Swift
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.")
|
|
}
|
|
}
|