kareman / SwiftShell

A Swift framework for shell scripting.
https://kareman.github.io/SwiftShell
MIT License
1.03k stars 87 forks source link

New syntax? #81

Closed armdn closed 4 years ago

armdn commented 4 years ago

In Swift 3 version of SwiftShell this code was working perfectly:

`let unavailState: String = run("/bin/bash", with: [ "-c", "/usr/local/bin/zpool status | grep state | grep -w UNAVAIL | wc -l"]) let trimUnavail = unavailState.trimmingCharacters(in: .whitespacesAndNewlines)

let degradedState: String = run("/bin/bash", with: [ "-c", "/usr/local/bin/zpool status | grep state | grep -w DEGRADED | wc -l"]) let trimDegraded = degradedState.trimmingCharacters(in: .whitespacesAndNewlines)

let offlineState: String = run("/bin/bash", with: ["-c", "/usr/local/bin/zpool status | grep state | grep -w OFFLINE | wc -l"]) let trimOffline = offlineState.trimmingCharacters(in: .whitespacesAndNewlines)

let faultedState: String = run("/bin/bash", with: ["-c", "/usr/local/bin/zpool status | grep state | grep -w FAULTED | wc -l"]) let trimFaulted = faultedState.trimmingCharacters(in: .whitespacesAndNewlines)

let removedState: String = run("/bin/bash", with: ["-c", "/usr/local/bin/zpool status | grep state | grep -w REMOVED | wc -l"]) let trimRemoved = removedState.trimmingCharacters(in: .whitespacesAndNewlines)

let onlineState: String = run("/bin/bash", with: ["-c", "/usr/local/bin/zpool status | grep state | grep -w ONLINE | wc -l"]) let trimOnline = onlineState.trimmingCharacters(in: .whitespacesAndNewlines) But now, it throw an error while compiling:Argument labels '(_:, with:)' do not match any available overloads`

So, what is new way to do the same thing?

kareman commented 4 years ago

Yes, there is a new syntax, you can read more about it here: https://github.com/kareman/SwiftShell .

So e.g. the first command will be:

let unavailState = run(bash: "/usr/local/bin/zpool status | grep state | grep -w UNAVAIL | wc -l").stdout
let trimUnavail = unavailState.trimmingCharacters(in: .whitespacesAndNewlines)
kareman commented 4 years ago

You may not even need to do the trimming yourself if the output is one line.