Skip to content

Commit

Permalink
Remove unavailable symbols (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
natecook1000 authored Sep 10, 2021
1 parent b77ea81 commit ddd45aa
Showing 1 changed file with 0 additions and 91 deletions.
91 changes: 0 additions & 91 deletions Sources/ArgumentParser/Parsable Properties/Flag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -532,97 +532,6 @@ extension Flag {
}
}

// - MARK: Unavailable CaseIterable/RawValue == String

extension Flag where Value: CaseIterable, Value: RawRepresentable, Value: Equatable, Value.RawValue == String {
/// Creates a property that gets its value from the presence of a flag,
/// where the allowed flags are defined by a case-iterable type.
///
/// - Parameters:
/// - name: A specification for what names are allowed for this flag.
/// - initial: A default value to use for this property. If `initial` is
/// `nil`, this flag is required.
/// - exclusivity: The behavior to use when multiple flags are specified.
/// - help: Information about how to use this flag.
@available(*, unavailable, message: "Add 'EnumerableFlag' conformance to your value type and, if needed, specify the 'name' of each case there.")
public init(
name: NameSpecification = .long,
default initial: Value? = nil,
exclusivity: FlagExclusivity = .exclusive,
help: ArgumentHelp? = nil
) {
self.init(_parsedValue: .init { key in
// This gets flipped to `true` the first time one of these flags is
// encountered.
var hasUpdated = false
let defaultValue = initial.map(String.init(describing:))

let args = Value.allCases.map { value -> ArgumentDefinition in
let caseKey = InputKey(rawValue: value.rawValue)
let help = ArgumentDefinition.Help(options: initial != nil ? .isOptional : [], help: help, defaultValue: defaultValue, key: key, isComposite: true)
return ArgumentDefinition.flag(name: name, key: key, caseKey: caseKey, help: help, parsingStrategy: .default, initialValue: initial, update: .nullary({ (origin, name, values) in
hasUpdated = try ArgumentSet.updateFlag(key: key, value: value, origin: origin, values: &values, hasUpdated: hasUpdated, exclusivity: exclusivity)
}))
}
return ArgumentSet(args)
})
}
}

extension Flag {
/// Creates a property that gets its value from the presence of a flag,
/// where the allowed flags are defined by a case-iterable type.
@available(*, unavailable, message: "Add 'EnumerableFlag' conformance to your value type and, if needed, specify the 'name' of each case there.")
public init<Element>(
name: NameSpecification = .long,
exclusivity: FlagExclusivity = .exclusive,
help: ArgumentHelp? = nil
) where Value == Element?, Element: CaseIterable, Element: Equatable, Element: RawRepresentable, Element.RawValue == String {
self.init(_parsedValue: .init { key in
// This gets flipped to `true` the first time one of these flags is
// encountered.
var hasUpdated = false

let args = Element.allCases.map { value -> ArgumentDefinition in
let caseKey = InputKey(rawValue: value.rawValue)
let help = ArgumentDefinition.Help(options: .isOptional, help: help, key: key, isComposite: true)
return ArgumentDefinition.flag(name: name, key: key, caseKey: caseKey, help: help, parsingStrategy: .default, initialValue: nil as Element?, update: .nullary({ (origin, name, values) in
hasUpdated = try ArgumentSet.updateFlag(key: key, value: value, origin: origin, values: &values, hasUpdated: hasUpdated, exclusivity: exclusivity)
}))
}
return ArgumentSet(args)
})
}

/// Creates an array property that gets its values from the presence of
/// zero or more flags, where the allowed flags are defined by a
/// `CaseIterable` type.
///
/// This property has an empty array as its default value.
///
/// - Parameters:
/// - name: A specification for what names are allowed for this flag.
/// - help: Information about how to use this flag.
@available(*, unavailable, message: "Add 'EnumerableFlag' conformance to your value type and, if needed, specify the 'name' of each case there.")
public init<Element>(
name: NameSpecification = .long,
help: ArgumentHelp? = nil
) where Value == Array<Element>, Element: CaseIterable, Element: RawRepresentable, Element.RawValue == String {
self.init(_parsedValue: .init { key in
let args = Element.allCases.map { value -> ArgumentDefinition in
let caseKey = InputKey(rawValue: value.rawValue)
let help = ArgumentDefinition.Help(options: .isOptional, help: help, key: key, isComposite: true)
return ArgumentDefinition.flag(name: name, key: key, caseKey: caseKey, help: help, parsingStrategy: .default, initialValue: [Element](), update: .nullary({ (origin, name, values) in
values.update(forKey: key, inputOrigin: origin, initial: [Element](), closure: {
$0.append(value)
})
}))
}
return ArgumentSet(args)
})
}
}

extension ArgumentDefinition {
static func flag<V>(name: NameSpecification, key: InputKey, caseKey: InputKey, help: Help, parsingStrategy: ArgumentDefinition.ParsingStrategy, initialValue: V?, update: Update) -> ArgumentDefinition {
return ArgumentDefinition(kind: .name(key: caseKey, specification: name), help: help, completion: .default, parsingStrategy: parsingStrategy, update: update, initial: { origin, values in
Expand Down

0 comments on commit ddd45aa

Please sign in to comment.