Files
SwiftLint/Source/swiftlint/Commands/GenerateDocsCommand.swift
T
JP Simard d2643db495 [Docs] Build docs using jazzy (#3016)
* Add `.jazzy.yaml` configuration file
* Update `swiftlint generate-docs` to write docs to a directory rather than a single file
* Add jazzy to the Gemfile
* Run `bundle update`
* Add CI job to run jazzy automatically and publish to GitHub Pages

![swiftlint-jazzy](https://user-images.githubusercontent.com/474794/71799038-fcf4e180-3008-11ea-81fa-3eb9cf296506.gif)
2020-01-07 20:31:29 -08:00

34 lines
1.1 KiB
Swift

import Commandant
import Foundation
import SwiftLintFramework
struct GenerateDocsCommand: CommandProtocol {
let verb = "generate-docs"
let function = "Generates markdown documentation for all rules"
func run(_ options: GenerateDocsOptions) -> Result<(), CommandantError<()>> {
let docs = RuleListDocumentation(masterRuleList)
do {
try docs.write(to: URL(fileURLWithPath: options.path))
} catch {
return .failure(.usageError(description: error.localizedDescription))
}
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: "rule_docs",
usage: "the directory where the documentation should be saved. defaults to `rule_docs`.")
}
}