diff --git a/SwiftShell/Files.swift b/SwiftShell/Files.swift index 42cda2e..f1e895f 100644 --- a/SwiftShell/Files.swift +++ b/SwiftShell/Files.swift @@ -35,27 +35,24 @@ public let tempdirectory: String = { return tempdirectory }() -public extension NSFileManager { +/** +The current working directory. - /** - The current working directory. - - Must be used instead of `run("cd ...")` because all the `run` commands are executed in a - separate process and changing the directory there will not affect the rest of the Swift script. - - This directory is also used as the base for relative URL's. - */ - public var workdirectory: String { - get { return File.currentDirectoryPath } - set { - if !File.changeCurrentDirectoryPath(newValue) { - printErrorAndExit("Could not change the working directory to \(newValue)") - } +Must be used instead of `run("cd ...")` because all the `run` commands are executed in a +separate process and changing the directory there will not affect the rest of the Swift script. +This directory is also used as the base for relative URL's. +*/ +public struct workdirectory { + public static func get() -> String { return File.currentDirectoryPath } + public static func set(newValue: String) { + if !File.changeCurrentDirectoryPath(newValue) { + printErrorAndExit("Could not change the working directory to \(newValue)") } } } + /** Allows for `"/directory" / "file.extension"` etc. */ public func / (leftpath: String, rightpath: String) -> String { return toURLOrError(leftpath).URLByAppendingPathComponent(rightpath).path! diff --git a/SwiftShellTests/Files_Tests.swift b/SwiftShellTests/Files_Tests.swift index 5dbf770..e893702 100644 --- a/SwiftShellTests/Files_Tests.swift +++ b/SwiftShellTests/Files_Tests.swift @@ -16,19 +16,19 @@ class Files_Tests: XCTestCase { } func testWorkDirectory_IsCurrentDirectory () { - XCTAssertEqual( File.workdirectory, NSFileManager.defaultManager().currentDirectoryPath ) + XCTAssertEqual( workdirectory.get(), NSFileManager.defaultManager().currentDirectoryPath ) } func testWorkDirectory_CanChange () { - File.workdirectory = ("/private/tmp") + workdirectory.set("/private/tmp") - XCTAssertEqual( File.workdirectory, "/private/tmp" ) + XCTAssertEqual( workdirectory.get(), "/private/tmp" ) XCTAssertEqual( $("pwd"), "/private/tmp" ) } func testURLConcatenationOperator () { XCTAssertEqual( "/directory" / "file.extension", "/directory/file.extension" ) XCTAssertEqual( "/root" / "directory" / "file.extension", "/root/directory/file.extension" ) - XCTAssertEqual( "directory" / "file.extension", File.workdirectory + "/directory/file.extension" ) + XCTAssertEqual( "directory" / "file.extension", workdirectory.get() + "/directory/file.extension" ) } }