Skip to content

Commit

Permalink
Add cd() (#13)
Browse files Browse the repository at this point in the history
* Add cd()

* Fixes Examples/cd.swift

* Change to public
  • Loading branch information
KS1019 authored Nov 4, 2023
1 parent bb20a3a commit 8594c13
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Examples/cd.swift
Original file line number Diff line number Diff line change
@@ -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: currentDir)
.exec("pwd")
.match(currentDir)
.exec("echo 'Test Success'")
.stdout()
4 changes: 3 additions & 1 deletion Scripts/ExamplesTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ html="<!doctype html>

try "$html" "../Examples/curl.swift"

try "Received input: hh. Test is working. Yay." "../Examples/stdin.swift" "hh"
try "Received input: hh. Test is working. Yay." "../Examples/stdin.swift" "hh"

try "Test Success" "../Examples/cd.swift"
12 changes: 12 additions & 0 deletions Sources/ScriptSwift/ExeternalCommands.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ShellOut

public extension Script {
func cd(to path: String) -> Script {
do {
try shellOut(to: "cd " + path)
return self
} catch {
return .init(failure: error)
}
}
}

0 comments on commit 8594c13

Please sign in to comment.