Skip to content

Commit

Permalink
✨ Add option to quickly get items for the latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
technocidal committed Sep 16, 2024
1 parent df5a255 commit dc4e165
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Sources/Changelog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit dc4e165

Please sign in to comment.