command line tool in swift

31
Command Line T ool in Swif t Mercari Inc. @kitasuke

Upload: yusuke-kita

Post on 19-Aug-2015

1.404 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Command Line Tool in swift

Command Line Tool in Swift

Mercari Inc. @kitasuke

Page 2: Command Line Tool in swift

CLI tool or script might be needed for pre-action before

build

Page 3: Command Line Tool in swift

Why using Swift?

Page 4: Command Line Tool in swift

First step to use Swift in your project

Page 5: Command Line Tool in swift

CLI tool, not Script4 dependency management

4 flexible extension

Page 6: Command Line Tool in swift

How developing with Xcode?

Page 8: Command Line Tool in swift

FrameworkCommandant is a Swift framework for parsing

command-line arguments

Page 9: Command Line Tool in swift

Project directory4 Carthage

4 xcodeproj

4 xcworkspace

4 Makefile

4 script

Page 10: Command Line Tool in swift

Workspace structure4 Main target

4 Static framework target

4 Test target

4 xcconfigs

4 framework projects

Page 11: Command Line Tool in swift

Configurations

Page 12: Command Line Tool in swift

Create a project

Page 13: Command Line Tool in swift

Clean up files and add main.swift

Page 14: Command Line Tool in swift

Add a framework

Page 15: Command Line Tool in swift

Run Carthagecarthage update --use-submodules

github "Carthage/Commandant"github "jspahrsummers/xcconfigs"github "ishkawa/APIKit"github "ikesyo/Himotoki"

Page 17: Command Line Tool in swift

Run bootstrap scriptobjc-build-scripts: standardize how Objective-C projects are

bootstrapped after cloning

Page 18: Command Line Tool in swift

New workspaceAdd all the projects into here

Page 19: Command Line Tool in swift

Add frameworksGeneral → Linked Frameworks

and Libraries

Page 20: Command Line Tool in swift

Copy frameworks in Build Phrases

Destination is frameworks

Page 21: Command Line Tool in swift

Runpath in Buld Settings for main target

/Library/Frameworks/***.framework/Versions/Current/Frameworks/

Page 22: Command Line Tool in swift

Embedded Content Contains Swift Code for framework

target

Set to YES, default is NO

Page 23: Command Line Tool in swift

Add components.plist for pkgbuild command<plist version="1.0"><array> <dict> <key>BundleIsVersionChecked</key> <false/> <key>BundleOverwriteAction</key> <string>upgrade</string> <key>ChildBundles</key> <array> <dict> <key>BundleOverwriteAction</key> <string></string> <key>RootRelativeBundlePath</key> <string>Library/Frameworks/***.framework/Versions/A/Frameworks/***.framework</string> </dict> </array> <key>RootRelativeBundlePath</key> <string>Library/Frameworks/***.framework</string> </dict></array></plist>

Page 24: Command Line Tool in swift

Run install commandpkgbuild --component-plist --identifier --install-location --root --version

Page 25: Command Line Tool in swift

Adding command

Page 26: Command Line Tool in swift

Using Commandantpublic protocol CommandType { typealias ClientError

/// The action that users should specify to use this subcommand (e.g., /// `help`). var verb: String { get }

/// A human-readable, high-level description of what this command is used /// for. var function: String { get }

/// Runs this subcommand in the given mode. func run(mode: CommandMode) -> Result<(), CommandantError<ClientError>>}

Page 27: Command Line Tool in swift

Debugging

Page 28: Command Line Tool in swift

Arguments Passed on Launch in scheme setting

Page 29: Command Line Tool in swift

Demo

Page 30: Command Line Tool in swift

Start your Swift life from now !

Page 31: Command Line Tool in swift

Thank you