diff --git a/Sources/Commandant/ArgumentProtocol.swift b/Sources/Commandant/ArgumentProtocol.swift index 84d7f73..cf73b25 100644 --- a/Sources/Commandant/ArgumentProtocol.swift +++ b/Sources/Commandant/ArgumentProtocol.swift @@ -31,32 +31,14 @@ extension String: ArgumentProtocol { } } -public extension RawRepresentable where Self.RawValue: StringProtocol, Self: ArgumentProtocol { - +extension RawRepresentable where RawValue: StringProtocol, Self: ArgumentProtocol { public static func from(string: String) -> Self? { - - guard let stringValue = Self.RawValue(string) - else { - return .none - } - - return Self(rawValue: stringValue) - + return RawValue(string).flatMap(Self.init(rawValue:)) } - } -public extension RawRepresentable where Self.RawValue: FixedWidthInteger, Self: ArgumentProtocol { - +extension RawRepresentable where RawValue: FixedWidthInteger, Self: ArgumentProtocol { public static func from(string: String) -> Self? { - - guard let intValue = Self.RawValue(string) - else { - return .none - } - - return Self(rawValue: intValue) - + return RawValue(string).flatMap(Self.init(rawValue:)) } - } diff --git a/Tests/CommandantTests/OptionsWithEnumProtocolSpec.swift b/Tests/CommandantTests/OptionsWithEnumProtocolSpec.swift index aed8ca2..650a17c 100644 --- a/Tests/CommandantTests/OptionsWithEnumProtocolSpec.swift +++ b/Tests/CommandantTests/OptionsWithEnumProtocolSpec.swift @@ -156,7 +156,6 @@ extension TestEnumOptions: CustomStringConvertible { } enum StrictStringValue: String, ArgumentProtocol { - static var name: String = "Strict string value: `foobar`, `bazbuzz`, `one`, `two`, `baz`, `a`, `b` or `c`" case foobar @@ -167,11 +166,9 @@ enum StrictStringValue: String, ArgumentProtocol { case a case b case c - } enum StrictIntValue: UInt8, ArgumentProtocol { - static var name: String = "Strict int value: `3`, `5`, `42`, `0`, `255`" case min = 0 @@ -179,5 +176,4 @@ enum StrictIntValue: UInt8, ArgumentProtocol { case giveFive = 5 case theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything = 42 case max = 255 - }