1/// What `covane publish` was asked to do, read from the arguments after the command word.
2public struct PublishOptions: Sendable, Equatable {
3 public static let commandWord = "publish"
4
5 public static let usage = """
6 usage: covane publish --site <report folder> --pages-branch <name> [--title <text>]
7 [--commit <sha>] [--subject <text>]
8 [--tests-outcome success|failure|skipped|cancelled]
9 [--report-outcome success|failure|skipped|cancelled]
10 [--runs-to-keep <n>]
11 """
12
13 /// The report folder to publish; unused, and so need not exist, when an outcome says
14 /// the run has no coverage.
15 public let siteFolder: String
16 public let pagesBranch: String
17 public let title: String
18 /// Nil to take the repository's current commit.
19 public let commit: String?
20 /// Nil to take the current commit's subject.
21 public let subject: String?
22 public let testsOutcome: ActionOutcome
23 public let reportOutcome: ActionOutcome
24 public let runsToKeep: Int
25
26 /// - Throws: `ReportOptionsError` for an unknown option, an option without its value,
27 /// a missing required option, an outcome that isn't one of the four, or a run count
28 /// that isn't a whole number of at least one.
2910 public init(arguments: [String]) throws {
3010 let values = try OptionValues(arguments: arguments, allowed: Self.options)
318 siteFolder = try values.required("--site")
327 pagesBranch = try values.required("--pages-branch")
336 title = values["--title"] ?? ReportOptions.defaultTitle
346 commit = values["--commit"]
356 subject = values["--subject"]
366 testsOutcome = try Self.outcome(values, "--tests-outcome")
375 reportOutcome = try Self.outcome(values, "--report-outcome")
385 runsToKeep = try Self.runsToKeep(values)
392 }
40
41 private static let options: Set = [
42 "--site", "--pages-branch", "--title", "--commit", "--subject", "--tests-outcome",
43 "--report-outcome", "--runs-to-keep",
44 ]
45
4611 private static func outcome(_ values: OptionValues, _ option: String) throws -> ActionOutcome {
4711 guard let value = values[option] else { return .success }
483 guard let outcome = ActionOutcome(rawValue: value) else {
491 throw ReportOptionsError.notAnOutcome(option: option, value: value)
502 }
512 return outcome
5211 }
53
545 private static func runsToKeep(_ values: OptionValues) throws -> Int {
555 let option = "--runs-to-keep"
565 guard let value = values[option] else { return PublishedLayout.defaultRunsToKeep }
574 guard let count = Int(value), count >= 1 else {
583 throw ReportOptionsError.notPositive(option: option, value: value)
593 }
601 return count
615 }
62}