From dc4e165141124f4ec5f5a04363aba02f151d5856 Mon Sep 17 00:00:00 2001 From: Johannes Ebeling Date: Mon, 16 Sep 2024 17:40:55 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20option=20to=20quickly=20get?= =?UTF-8?q?=20items=20for=20the=20latest=20release?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Changelog.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/Changelog.swift b/Sources/Changelog.swift index 2c71c22..a453a55 100644 --- a/Sources/Changelog.swift +++ b/Sources/Changelog.swift @@ -18,12 +18,15 @@ struct Changelog: ParsableCommand { enum Release: ExpressibleByArgument, CustomStringConvertible { case unreleased + case latest case release(String) var description: String { switch self { case .unreleased: return defaultValueDescription + case .latest: + return "latest" case let .release(value): return value } @@ -37,10 +40,21 @@ struct Changelog: ParsableCommand { switch argument.lowercased() { case "unreleased": self = .unreleased + case "latest": + self = .latest default: self = .release(argument) } } + + func filterForFirstMatching(_ heading: Heading) -> Bool { + switch self { + case .latest: + heading.plainText.lowercased() != Release.unreleased.description + case .unreleased, .release: + heading.plainText.lowercased() == description + } + } } @Argument(help: "Path to Changelog.md file") @@ -60,7 +74,7 @@ struct Changelog: ParsableCommand { let heading = document.children .compactMap { $0 as? Heading } .filter { $0.level == 2 } - .first { $0.plainText.lowercased() == release.description } + .first { release.filterForFirstMatching($0) } guard let heading else { throw ValidationError("Changelog does not contain '\(release.description.localizedCapitalized)' section")