-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clean/rc argument parser #23
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3bd789e
drafting arguments parser adoption
elfenlaid 3af86b6
support named colors arguments cli
elfenlaid 2f7ed29
streamline processing by stripping factory completions
elfenlaid 7f7920e
support icon set in arguments parser
elfenlaid cc3c7aa
switch to iconset struct
elfenlaid 176892d
fix path extension handling
elfenlaid a98ea71
extract commands' process to a pipeline
elfenlaid f2c87ed
shuffle cli model files to helpers directory
elfenlaid 389470f
use pipeline in arguments CLI
elfenlaid 511f4a6
hack around logger's verbose flag
elfenlaid d675b46
add compilation flag to swift on to arguments parser
elfenlaid c617498
add initial execution log
elfenlaid adc5a14
match logging with original cli
elfenlaid 49fb264
tweak colors help section
elfenlaid 27e0733
replace colors order misspell
elfenlaid 9953f2b
tweak angle option flag comments
elfenlaid 2a2345d
redo CLI position argument handling
elfenlaid 75fec0c
trim a detailed explanation of hex regexp
elfenlaid b733332
by command position argument handling
elfenlaid 8efb0a6
fix validation error misspell
elfenlaid cf0957d
cleaned up header comments
elfenlaid c89b0f1
Merge pull request #14 from elfenlaid/argument-parser
arthurpalves 577b54a
drop SwiftCLI arguments handling
elfenlaid 1b43752
explicitly specify default values for color arguments
elfenlaid 22e6e36
close default bracket
elfenlaid 916da00
Merge pull request #18 from elfenlaid/drop-swiftcli-arguments-handling
arthurpalves 80a7411
Merge pull request #19 from elfenlaid/default-color-values
arthurpalves 807bd37
merge: merge master back
arthurpalves f32222e
formatting: SwiftFormat adjustments
arthurpalves File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// | ||
// Badgy.swift | ||
// Badgy | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2020 Arthur Alves | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the Software), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
import ArgumentParser | ||
import Foundation | ||
import PathKit | ||
|
||
struct Badgy: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
abstract: "A command-line tool to add labels to your app icon", | ||
version: "0.1.4", | ||
subcommands: [Long.self, Small.self], | ||
defaultSubcommand: Long.self | ||
) | ||
} | ||
|
||
extension Badgy { | ||
struct Options: ParsableArguments { | ||
@Argument(help: "Specify badge text") | ||
var label: String | ||
|
||
@Argument(help: "Specify path to icon with format .png | .jpg | .jpeg | .appiconset", transform: Icon.init(path:)) | ||
var icon: Icon | ||
|
||
@Option(help: """ | ||
Specify a valid hex color code in a case insensitive format: '#rrggbb' | '#rrggbbaa' | ||
or | ||
Provide a named color: 'snow' | 'snow1' | ... | ||
Complete list of named colors: https://imagemagick.org/script/color.php#color_names | ||
(default: randomly selected from \(Factory.colors.joined(separator: " | "))) | ||
""") | ||
var color: ColorCode? | ||
|
||
@Option(default: "white", help: """ | ||
Specify a valid hex color code in a case insensitive format: '#rrggbb' | '#rrggbbaa' | ||
or | ||
Provide a named color: 'snow' | 'snow1' | ... | ||
Complete list of named colors: https://imagemagick.org/script/color.php#color_names | ||
""") | ||
var tintColor: ColorCode | ||
|
||
@Flag(help: "Indicates Badgy should replace the input icon") | ||
var replace: Bool | ||
|
||
@Flag(help: "Log tech details for nerds") | ||
var verbose: Bool | ||
|
||
func validate() throws { | ||
guard DependencyManager().areDependenciesInstalled() else { | ||
throw ValidationError("Missing dependencies. Run: 'brew install imagemagick'") | ||
} | ||
|
||
Logger.shared.verbose = verbose | ||
} | ||
} | ||
} | ||
|
||
extension Badgy { | ||
struct Long: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
abstract: "Add rectangular label to app icon" | ||
) | ||
|
||
@OptionGroup() | ||
var options: Badgy.Options | ||
|
||
@Option(default: .bottom, help: "Position on which to place the badge. Supported positions: \(Position.longLabelPositions.formatted())") | ||
var position: Position | ||
|
||
@Option(default: 0, help: "The rotation angle of the badge in degrees range of -180 ... 180") | ||
var angle: Int | ||
|
||
func validate() throws { | ||
guard options.label.count <= 4 else { | ||
throw ValidationError("Label should contain maximum 4 characters") | ||
} | ||
|
||
guard position.isValidForLongLabels else { | ||
throw ValidationError("Invalid provided position, supported positions are: \(Position.longLabelPositions.formatted())") | ||
} | ||
|
||
let validAngleRange = -180 ... 180 | ||
guard validAngleRange.contains(angle) else { | ||
throw ValidationError("Angle should be within range: \(validAngleRange)") | ||
} | ||
} | ||
|
||
func run() throws { | ||
Logger.shared.logSection("$ ", item: "badgy long \"\(options.label)\" \"\(options.icon.path)\"", color: .ios) | ||
|
||
var pipeline = IconSignPipeline.make(withOptions: options) | ||
pipeline.position = position | ||
pipeline.angle = angle | ||
|
||
try pipeline.execute() | ||
} | ||
} | ||
} | ||
|
||
extension Badgy { | ||
struct Small: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
abstract: "Add small square label to app icon" | ||
) | ||
|
||
@OptionGroup() | ||
var options: Badgy.Options | ||
|
||
@Option(default: .bottomLeft, help: "Position on which to place the badge. Supported positions: \(Position.allCases.formatted())") | ||
var position: Position | ||
|
||
func validate() throws { | ||
guard options.label.count <= 1 else { | ||
throw ValidationError("Label should contain maximum 1 character") | ||
} | ||
} | ||
|
||
func run() throws { | ||
Logger.shared.logSection("$ ", item: "badgy small \"\(options.label)\" \"\(options.icon.path)\"", color: .ios) | ||
|
||
var pipeline = IconSignPipeline.make(withOptions: options) | ||
pipeline.position = position | ||
|
||
try pipeline.execute() | ||
} | ||
} | ||
} | ||
|
||
extension Position: ExpressibleByArgument {} | ||
|
||
private extension IconSignPipeline { | ||
static func make(withOptions options: Badgy.Options) -> IconSignPipeline { | ||
var pipeline = IconSignPipeline(icon: options.icon, label: options.label) | ||
|
||
pipeline.color = options.color?.value | ||
pipeline.tintColor = options.tintColor.value | ||
pipeline.replace = options.replace | ||
|
||
return pipeline | ||
} | ||
} | ||
|
||
private extension Position { | ||
static let longLabelPositions: Set<Position> = Set([ | ||
.top, .left, .bottom, .right, .center | ||
]) | ||
|
||
var isValidForLongLabels: Bool { | ||
Position.longLabelPositions.contains(self) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Danger: This can cause Xcode to not even want to start building: https://stackoverflow.com/q/63079909/3939277
adding
.git
to the end of the URL will solve that, and also might fix the thing down below where you had to use.product
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, a nice catch :)
Converted into an issue #24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to help 😁