Skip to content
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

Remove automatically anonymous playground file instead of using --no-save option #7

Merged
merged 2 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ Xcode 8 is required.
```sh
# Create 'UIKitDemo.playground' for iOS
$ toybox create UIKitDemo
# Create new Playground named with timestamp
# Create a new Playground which is not saved
$ toybox create
# Create 'SpriteKit.playground' for macOS
$ toybox create SpriteKitDemo --platform macos
# Overwrite existing playground 'UIKitDemo'
$ toybox create UIKitDemo -f
# Create but don't open with Xcode
$ toybox create UIKitDemo --no-open
# Create and remove the file automatically
$ toybox create UIKitDemo --no-save
# Create and open with specific Xcode
$ toybox create UIKitDemo --xcode-path /Application/Xcode7.3.app
# Create Playground from standard input
Expand Down
16 changes: 7 additions & 9 deletions Sources/toybox/Commands/Create.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ struct CreateOptions: OptionsProtocol {
let noOpen: Bool
let enableStandardInput: Bool
let xcodePath: URL?
let noSave: Bool

static func create(_ platform: Platform) -> (String?) -> ([String]) -> (Bool) -> (Bool) -> (Bool) -> (Bool) -> CreateOptions {
return { xcodePathString in { fileNames in { force in { noOpen in { standardInput in { noSave in
static func create(_ platform: Platform) -> (String?) -> ([String]) -> (Bool) -> (Bool) -> (Bool) -> CreateOptions {
return { xcodePathString in { fileNames in { force in { noOpen in { standardInput in
let xcodePath: URL?
if let xcodePathString = xcodePathString {
xcodePath = URL(fileURLWithPath: xcodePathString)
Expand All @@ -26,9 +25,8 @@ struct CreateOptions: OptionsProtocol {
force: force,
noOpen: noOpen,
enableStandardInput: standardInput,
xcodePath: xcodePath,
noSave: noSave)
} } } } }
xcodePath: xcodePath)
} } } }
}
}

Expand All @@ -40,7 +38,6 @@ struct CreateOptions: OptionsProtocol {
<*> m <| Switch(flag: "f", key: "force", usage: "Whether to overwrite existing playground")
<*> m <| Switch(key: "no-open", usage: "Whether to open new playground")
<*> m <| Switch(key: "input", usage: "Whether to enable standard input")
<*> m <| Switch(flag: "n", key: "no-save", usage: "Remove playground file automatically")
}
}

Expand All @@ -58,7 +55,8 @@ struct CreateCommand: CommandProtocol {
}

let fileName = options.fileName
switch handler.create(fileName, for: options.platform, force: options.force, temporary: options.noSave) {
let temporary = (fileName == nil)
switch handler.create(fileName, for: options.platform, force: options.force, temporary: temporary) {
case let .success(playground):

if options.enableStandardInput {
Expand All @@ -72,7 +70,7 @@ struct CreateCommand: CommandProtocol {
if !options.noOpen {
_ = handler.open(playground.name,
with: options.xcodePath,
temporary: options.noSave)
temporary: temporary)
}
return .success()
case let .failure(error):
Expand Down