Rename ‘$’ to ‘run’.

Trying to not repeat the mistakes of bash shell scripting here.
This commit is contained in:
Kare Morstol
2015-09-02 17:34:40 +02:00
parent a8bfc6b1a6
commit 239d32edfd
4 changed files with 18 additions and 16 deletions
+9 -7
View File
@@ -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))
}
}
+1 -1
View File
@@ -59,7 +59,7 @@
BA2E3B421B5C3635001ED175 /* XCTestCase_Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestCase_Additions.swift; sourceTree = "<group>"; };
BA2E3B4E1B5C380C001ED175 /* Test area 2.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = "Test area 2.playground"; path = "Misc/Test area 2.playground"; sourceTree = "<group>"; };
BA2E3B4F1B5C450C001ED175 /* Context.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = "<group>"; };
BAE03DBA1B5C6B7200D731A0 /* Context_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context_Tests.swift; sourceTree = "<group>"; };
BAE03DBA1B5C6B7200D731A0 /* Context_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Context_Tests.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
+7 -7
View File
@@ -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" )
}
}
+1 -1
View File
@@ -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 )
}
}