1/// The `--option value` pairs of a command whose options each take one value, once.
2struct OptionValues {
321 private var values: [String: String] = [:]
4
5 /// - Throws: `ReportOptionsError` for an option outside `allowed` or without its value.
621 init(arguments: [String], allowed: Set<String>) throws {
721 var index = arguments.startIndex
872 while index < arguments.endIndex {
957 let option = arguments[index]
1057 guard allowed.contains(option) else {
113 throw ReportOptionsError.unknownOption(option)
1254 }
1354 guard index + 1 < arguments.endIndex else {
143 throw ReportOptionsError.missingValue(option: option)
1551 }
1651 values[option] = arguments[index + 1]
1751 index += 2
1851 }
1915 }
20
2142 subscript(option: String) -> String? { values[option] }
22
2328 func required(_ option: String) throws -> String {
2428 guard let value = values[option] else { throw ReportOptionsError.missingOption(option) }
2523 return value
2628 }
27}