Allow to pass a rule identifier to the `swiftlint docs` command (#4710)

This commit is contained in:
Danny Mösch 2023-02-07 00:01:52 +01:00 committed by GitHub
parent 5af4291b53
commit aafc574e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -41,6 +41,11 @@
[Julioacarrettoni](https://github.com/Julioacarrettoni) [Julioacarrettoni](https://github.com/Julioacarrettoni)
[#4624](https://github.com/realm/SwiftLint/pull/4624) [#4624](https://github.com/realm/SwiftLint/pull/4624)
* Allow to pass a rule identifier to the `swiftlint docs` command to open its
specific documentation website, e.g. `swiftlint docs for_where`.
[SimplyDanny](https://github.com/SimplyDanny)
[#4707](https://github.com/realm/SwiftLint/issues/4707)
* Allow new Quick APIs `aroundEach` and `justBeforeEach` for * Allow new Quick APIs `aroundEach` and `justBeforeEach` for
`quick_discouraged_call`. `quick_discouraged_call`.
[David Steinacher](https://github.com/stonko1994) [David Steinacher](https://github.com/stonko1994)

View File

@ -1,5 +1,6 @@
import ArgumentParser import ArgumentParser
import Foundation import Foundation
import SwiftLintFramework
extension SwiftLint { extension SwiftLint {
struct Docs: ParsableCommand { struct Docs: ParsableCommand {
@ -7,8 +8,20 @@ extension SwiftLint {
abstract: "Open SwiftLint documentation website in the default web browser" abstract: "Open SwiftLint documentation website in the default web browser"
) )
@Argument(help: "The identifier of the rule to open the documentation for")
var ruleID: String?
func run() throws { func run() throws {
open(URL(string: "https://realm.github.io/SwiftLint")!) var subPage = ""
if let ruleID {
if primaryRuleList.list[ruleID] == nil {
queuedPrintError("There is no rule named '\(ruleID)'. Opening rule directory instead.")
subPage = "rule-directory.html"
} else {
subPage = ruleID + ".html"
}
}
open(URL(string: "https://realm.github.io/SwiftLint/\(subPage)")!)
ExitHelper.successfullyExit() ExitHelper.successfullyExit()
} }
} }