-
Notifications
You must be signed in to change notification settings - Fork 88
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
Replace Commander library by ArgumentParser #70
Merged
Merged
Changes from all commits
Commits
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 |
---|---|---|
@@ -1,35 +1,56 @@ | ||
import AppIconCore | ||
import Commander | ||
|
||
let main = command( | ||
Argument<String>("base image (1024x1024.png)", description: "The path of the base image"), | ||
Option("icon-name", default: "AppIcon", description: "The name of the generated image"), | ||
Option("output-path", default: "AppIcon", description: "The path of the generated appiconset"), | ||
Flag("ipad", description: "Whether or not to generate iPad icons"), | ||
Flag("mac", description: "Whether or not to generate Mac icons"), | ||
Flag("watch", description: "Whether or not to generate Apple Watch icons") | ||
) { base, iconName, path, ipad, mac, watch in | ||
guard base.hasSuffix(".png") else { | ||
throw ArgumentError.missingValue(argument: "base image (1024x1024.png)") | ||
} | ||
import ArgumentParser | ||
|
||
let outputExpansion = ".appiconset" | ||
let outputPath = path.hasSuffix(outputExpansion) ? path : "\(path)\(outputExpansion)" | ||
let platforms = Platform.platforms(ipad: ipad, mac: mac, watch: watch) | ||
struct AppIcon: ParsableCommand { | ||
static let configuration = CommandConfiguration( | ||
commandName: "appicon", | ||
abstract: "AppIcon generates *.appiconset contains each resolution image for iOS", | ||
version: "1.0.5" | ||
) | ||
|
||
do { | ||
try ImageExtractor.extract(input: (base, platforms), output: (iconName, outputPath)) | ||
} catch { | ||
print("Image Extraction Error has occured 😱") | ||
} | ||
@Argument(help: "The path to the base image (1024x1024.png)") | ||
var image: String | ||
|
||
do { | ||
try JSONExtractor.extract(input: platforms, output: (iconName, outputPath)) | ||
} catch { | ||
print("JSON Extraction Error has occured 😱") | ||
} | ||
@Option(help: "The name of the generated image") | ||
var iconName = "AppIcon" | ||
|
||
@Option(help: "The path of the generated appiconset") | ||
var outputPath = "AppIcon" | ||
|
||
@Flag(help: "Whether or not to generate iPad icons") | ||
var ipad = false | ||
|
||
@Flag(help: "Whether or not to generate Mac icons") | ||
var mac = false | ||
|
||
print("\(outputPath) has been generated 🎉") | ||
@Flag(help: "Whether or not to generate Apple Watch icons") | ||
var watch = false | ||
|
||
func run() throws { | ||
guard image.hasSuffix(".png") else { | ||
throw ValidationError("image path should have .png extension") | ||
} | ||
|
||
let outputExpansion = ".appiconset" | ||
let outputPath = self.outputPath.hasSuffix(outputExpansion) ? self.outputPath : "\(self.outputPath)\(outputExpansion)" | ||
let platforms = Platform.platforms(ipad: ipad, mac: mac, watch: watch) | ||
|
||
do { | ||
try ImageExtractor.extract(input: (image, platforms), output: (iconName, outputPath)) | ||
} catch { | ||
print("Image Extraction Error has occured 😱") | ||
throw ExitCode(1) | ||
} | ||
|
||
do { | ||
try JSONExtractor.extract(input: platforms, output: (iconName, outputPath)) | ||
} catch { | ||
print("JSON Extraction Error has occured 😱") | ||
throw ExitCode(1) | ||
} | ||
|
||
print("\(outputPath) has been generated 🎉") | ||
} | ||
} | ||
|
||
main.run("1.0.4") | ||
AppIcon.main() |
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.
I also think in that and L48 cases program flow should be aborted to prevent wrong success info printing