diff --git a/Examples/cd.swift b/Examples/cd.swift new file mode 100644 index 0000000..2946f00 --- /dev/null +++ b/Examples/cd.swift @@ -0,0 +1,13 @@ +#!/usr/bin/swift sh + +import ScriptSwift // KS1019/Script.swift ~> main + +let currentDir = Script().exec("pwd").asString() + +let d = Script() + .cd(to: "../") + .cd(to: "./") + .exec("pwd") + .match(currentDir) + .exec("echo 'Test Success'") + .stdout() diff --git a/Scripts/ExamplesTest.sh b/Scripts/ExamplesTest.sh index 7682092..2696d1a 100644 --- a/Scripts/ExamplesTest.sh +++ b/Scripts/ExamplesTest.sh @@ -72,4 +72,6 @@ html=" try "$html" "../Examples/curl.swift" -try "Received input: hh. Test is working. Yay." "../Examples/stdin.swift" "hh" \ No newline at end of file +try "Received input: hh. Test is working. Yay." "../Examples/stdin.swift" "hh" + +try "Test Success" "../Examples/cd.swift" diff --git a/Sources/ScriptSwift/ExeternalCommands.swift b/Sources/ScriptSwift/ExeternalCommands.swift new file mode 100644 index 0000000..8dfcd60 --- /dev/null +++ b/Sources/ScriptSwift/ExeternalCommands.swift @@ -0,0 +1,12 @@ +import ShellOut + +extension Script { + public func cd(to path: String) -> Script { + do { + try shellOut(to: "cd " + path) + return self + } catch { + return .init(failure: error) + } + } +}