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
Changes from 1 commit
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
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