Upgrade to Pro — share decks privately, control downloads, hide ads and more …

potatotips #41: SwiftPM - コマンドラインツール作成入門

potatotips #41: SwiftPM - コマンドラインツール作成入門

Takeshi Ihara

June 13, 2017
Tweet

More Decks by Takeshi Ihara

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • Takeshi Ihara • Recruit Marketing Partners • iOS

    Engineer • Twitter: @nonchalant0303 • GitHub: @Nonchalant
  2. import PackageDescription let package = Package( name: "AppIcon", targets: [

    Target( name: "AppIcon", dependencies: ["AppIconCore"] ), Target(name: "AppIconCore") ], dependencies: [ .Package(url: "https://github.com/kylef/Commander", majorVersion: 0), .Package(url: "https://github.com/kareman/SwiftShell.git", "3.0.0"), .Package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", versions: Version(1, 0, 0)..<Version(3, .max, .max)) ] )
  3. import PackageDescription let package = Package( name: "AppIcon", targets: [

    Target( name: "AppIcon", dependencies: ["AppIconCore"] ), Target(name: "AppIconCore") ], dependencies: [ .Package(url: "https://github.com/kylef/Commander", majorVersion: 0), .Package(url: "https://github.com/kareman/SwiftShell.git", "3.0.0"), .Package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", versions: Version(1, 0, 0)..<Version(3, .max, .max)) ] )
  4. import PackageDescription let package = Package( name: "AppIcon", targets: [

    Target( name: "AppIcon", dependencies: ["AppIconCore"] ), Target(name: "AppIconCore") ], dependencies: [ .Package(url: "https://github.com/kylef/Commander", majorVersion: 0), .Package(url: "https://github.com/kareman/SwiftShell.git", "3.0.0"), .Package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", versions: Version(1, 0, 0)..<Version(3, .max, .max)) ] )
  5. import Commander import AppIconCore let main = command(Argument<String>("base image (1024x1024.png)",

    description: "The name of base image"), Option("icon-name", "AppIcon", description: "The name of generated icon name"), Option("output-path", "AppIcon", description: "The name of generated appiconset name"), Flag("ipad", description: "Whether or not to generate ipad icon")) { base, iconName, path, ipad in guard base.hasSuffix(".png") else { throw ArgumentError.missingValue(argument: "base image (1024x1024.png)") } let outputPath = "\(path).appiconset" do { try ImageExtractor.extract(input: (base, ipad), output: (iconName, outputPath)) } catch { print("Image Extraction Error is occured ") } do { try JSONExtractor.extract(input: ipad, output: (iconName, outputPath)) } catch { print("JSON Extraction Error is occured ") } print("\(outputPath) is generated ") } main.run() ը૾Λॻ͖ग़͍ͯ͠Δ $POUFOUTKTPOΛॻ͖ग़͍ͯ͠Δ ૉࡐͷύεΛड͚औ͍ͬͯΔ