-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from elfenlaid/handle-color-argument
#1 specify color for badge and text
- Loading branch information
Showing
7 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Badgy | ||
// | ||
// Created by Arthur Alves on 30/05/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Thanks to [How to use regular expressions in swift | Paul Hudson ](https://www.hackingwithswift.com/articles/108/how-to-use-regular-expressions-in-swift) | ||
internal extension NSRegularExpression { | ||
convenience init(_ pattern: String) { | ||
do { | ||
try self.init(pattern: pattern) | ||
} catch { | ||
preconditionFailure("Illegal regular expression: \(pattern).") | ||
} | ||
} | ||
|
||
func matches(_ string: String) -> Bool { | ||
let range = NSRange(location: 0, length: string.utf16.count) | ||
return firstMatch(in: string, options: [], range: range) != nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Badgy | ||
// | ||
// Created by Arthur Alves on 30/05/2020. | ||
// | ||
|
||
import Foundation | ||
import SwiftCLI | ||
|
||
extension Validation where T == String { | ||
static func hexColorCode() -> Self { | ||
let message = "Specify valid hex color code in a case insensitive format '#rrbbgg' | '#rrbbggaa'" | ||
|
||
return Validation<String>.custom(message) { (input) in | ||
guard NSRegularExpression.hexColorCode.matches(input) else { | ||
Logger.shared.logError("❌ ", item: "Input color '\(input)' doesn't have a valid format") | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
} | ||
} | ||
|
||
private extension NSRegularExpression { | ||
/// `^` asserts position at start of a line | ||
/// `#` matches the character # literally | ||
/// | ||
/// `(:?[0-9a-fA-F]{2})` | ||
/// - `(:?)` denotes a non-capturing group | ||
/// - `[0-9a-fA-F]` match a single character present in the list below | ||
/// - `{2}` - matches exactly 2 times | ||
/// | ||
/// `{3,4}` - matches between 3 and 4 times, as many times as possible | ||
/// | ||
/// Additional explanation at [regex101](https://regex101.com/) | ||
static let hexColorCode = NSRegularExpression("^#(?:[0-9a-fA-F]{2}){3,4}$") | ||
} |