mirror of
https://github.com/apple/swift-argument-parser.git
synced 2026-06-06 20:18:23 +00:00
Clean up InputOrigin by removing unused code. (#21)
This commit is contained in:
@@ -16,19 +16,11 @@
|
||||
/// This is usually an index into the `SplitArguments`.
|
||||
/// In some cases it can be multiple indices.
|
||||
struct InputOrigin: Equatable, ExpressibleByArrayLiteral {
|
||||
enum Element: Comparable, Hashable {
|
||||
enum Element: Hashable {
|
||||
case argumentIndex(SplitArguments.Index)
|
||||
}
|
||||
|
||||
private var _elements: Set<Element> = []
|
||||
var elements: [Element] {
|
||||
get {
|
||||
Array(_elements).sorted()
|
||||
}
|
||||
set {
|
||||
_elements = Set(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
}
|
||||
@@ -41,20 +33,20 @@ struct InputOrigin: Equatable, ExpressibleByArrayLiteral {
|
||||
_elements = Set([element])
|
||||
}
|
||||
|
||||
init(arrayLiteral elements: InputOrigin.Element...) {
|
||||
init(arrayLiteral elements: Element...) {
|
||||
self.init(elements: elements)
|
||||
}
|
||||
|
||||
static func argumentIndex(_ index: SplitArguments.Index) -> InputOrigin {
|
||||
return InputOrigin(elements: [.argumentIndex(index)])
|
||||
|
||||
init(argumentIndex: SplitArguments.Index) {
|
||||
self.init(element: .argumentIndex(argumentIndex))
|
||||
}
|
||||
|
||||
mutating func insert(_ other: InputOrigin.Element) {
|
||||
mutating func insert(_ other: Element) {
|
||||
guard !_elements.contains(other) else { return }
|
||||
_elements.insert(other)
|
||||
}
|
||||
|
||||
func inserting(_ other: InputOrigin.Element) -> InputOrigin {
|
||||
func inserting(_ other: Element) -> Self {
|
||||
guard !_elements.contains(other) else { return self }
|
||||
var result = self
|
||||
result.insert(other)
|
||||
@@ -64,27 +56,8 @@ struct InputOrigin: Equatable, ExpressibleByArrayLiteral {
|
||||
mutating func formUnion(_ other: InputOrigin) {
|
||||
_elements.formUnion(other._elements)
|
||||
}
|
||||
|
||||
func union(_ other: InputOrigin) -> InputOrigin {
|
||||
var result = self
|
||||
result._elements.formUnion(other._elements)
|
||||
return result
|
||||
}
|
||||
|
||||
func isSubset(of other: Self) -> Bool {
|
||||
return _elements.isSubset(of: other._elements)
|
||||
}
|
||||
|
||||
|
||||
func forEach(_ closure: (Element) -> Void) {
|
||||
_elements.forEach(closure)
|
||||
}
|
||||
}
|
||||
|
||||
extension InputOrigin.Element {
|
||||
static func < (lhs: Self, rhs: Self) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case (.argumentIndex(let l), .argumentIndex(let r)):
|
||||
return l < r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ extension SplitArguments {
|
||||
input = originalInput[index.inputIndex.rawValue]
|
||||
}
|
||||
}
|
||||
return (.argumentIndex(index), input)
|
||||
return (.init(argumentIndex: index), input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user