diff --git a/SwiftShell/Command.swift b/SwiftShell/Command.swift index 9b7bf71..1824347 100644 --- a/SwiftShell/Command.swift +++ b/SwiftShell/Command.swift @@ -8,8 +8,8 @@ import Foundation -/** -Print message to standard error and halt execution. +/** +Print message to standard error and halt execution. - parameter errormessage: the error message. - parameter errorcode: exit code for the entire program. Defaults to 1. @@ -40,9 +40,11 @@ extension ShellContextType { func setupTask (bash bashcommand: String) -> NSTask { return setupTask("/bin/bash", args: ["-c", bashcommand]) } +} +extension ShellContextType { - private func outputFrom$ (task: NSTask) -> String { + private func outputFromRun (task: NSTask) -> String { let output = NSPipe () task.standardOutput = output task.standardError = output @@ -66,8 +68,8 @@ extension ShellContextType { - parameter args: the arguments, one string for each. - returns: standard output and standard error in one string, trimmed of whitespace and newline if it is single-line. */ - public func $ (executable: String, _ args: String ...) -> String { - return outputFrom$(setupTask(executable, args: args)) + public func run (executable: String, _ args: String ...) -> String { + return outputFromRun(setupTask(executable, args: args)) } /** @@ -75,8 +77,8 @@ extension ShellContextType { - returns: standard output and standard error in one string, trimmed of whitespace and newline if it is single-line. */ - public func $ (bash bashcommand: String) -> String { - return outputFrom$(setupTask(bash: bashcommand)) + public func run (bash bashcommand: String) -> String { + return outputFromRun(setupTask(bash: bashcommand)) } } diff --git a/SwiftShell2.xcodeproj/project.pbxproj b/SwiftShell2.xcodeproj/project.pbxproj index 07b7a46..3e8d148 100644 --- a/SwiftShell2.xcodeproj/project.pbxproj +++ b/SwiftShell2.xcodeproj/project.pbxproj @@ -59,7 +59,7 @@ BA2E3B421B5C3635001ED175 /* XCTestCase_Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestCase_Additions.swift; sourceTree = ""; }; BA2E3B4E1B5C380C001ED175 /* Test area 2.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = "Test area 2.playground"; path = "Misc/Test area 2.playground"; sourceTree = ""; }; BA2E3B4F1B5C450C001ED175 /* Context.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = ""; }; - BAE03DBA1B5C6B7200D731A0 /* Context_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context_Tests.swift; sourceTree = ""; }; + BAE03DBA1B5C6B7200D731A0 /* Context_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Context_Tests.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ diff --git a/SwiftShellTests/Command_Tests.swift b/SwiftShellTests/Command_Tests.swift index 614cf8a..3dbe2e8 100644 --- a/SwiftShellTests/Command_Tests.swift +++ b/SwiftShellTests/Command_Tests.swift @@ -9,18 +9,18 @@ import SwiftShell import XCTest -class Command_Tests: XCTestCase { +class Run_Tests: XCTestCase { - func test$BashCommand () { - XCTAssertEqual( main.$(bash:"echo one"), "one" ) + func testBashCommand () { + XCTAssertEqual( main.run(bash:"echo one"), "one" ) } - func testSingleline$Command () { - XCTAssertEqual( main.$("/bin/echo", "one", "two"), "one two" ) + func testSinglelineOutput () { + XCTAssertEqual( main.run("/bin/echo", "one", "two"), "one two" ) } - func testMultiline$Command () { - XCTAssertEqual( main.$("/bin/echo", "one\ntwo"), "one\ntwo\n" ) + func testMultilineOutput () { + XCTAssertEqual( main.run("/bin/echo", "one\ntwo"), "one\ntwo\n" ) } } diff --git a/SwiftShellTests/Context_Tests.swift b/SwiftShellTests/Context_Tests.swift index e192f07..bcf9984 100644 --- a/SwiftShellTests/Context_Tests.swift +++ b/SwiftShellTests/Context_Tests.swift @@ -19,7 +19,7 @@ class Context_Tests: XCTestCase { main.currentdirectory = "/tmp" XCTAssertEqual( main.currentdirectory, "/private/tmp" ) - XCTAssertEqual( main.$("/bin/pwd"), "/tmp" ) + XCTAssertEqual( main.run("/bin/pwd"), "/tmp" ) XCTAssertEqual( main.currentdirectory, NSFileManager.defaultManager().currentDirectoryPath ) } }