Comments (4)
I wanted user input for marathon a while back and I saw this and thought I would press on and make a pull request for ShellOut. I didn't even look here or for existing pull requests, so I've already gone ahead and built a pull request implementing an approach to this.
from shellout.
Hey @rob-nash, sorry I missed your comment.
This might be controversial but I want to ask, do we need a top level async API in shellout?
I get that shellout needs to support read_line and other blocking api calls but do we want this to work in a synchronous way?
I'd like to figure out if there is a way this could just work
// my-script
func main() {
let answer = try! shellOut("./ask-script")
print(answer)
}
//ask-script
func main() {
let answer = readline()
print(answer)
}
If shell out supported this use case with the existing synchronous api would we want a shellOutAsync method? I’m potentially missing some key use case, so do let me know.
If we do need both sync & async shellout methods then imo we should ensure it's clear in the method name. I also want to suggest that any new API should support streaming output through a closure so that consumers don't need to use a file handler.
Something like:
Sync + streaming output
@discardableResult
public func shellOut(to command: String,
arguments: [String] = [],
at path: String = ".",
withOutput output: (String) -> Void) -> throws String {}
// run 1st long running command
try! shellOut("docker compose .") { output in
// print output as it arrives
print(output)
}
// second command won't start until first command is finished.
try! shellOut("docker public") { output in
print(output)
}
// We can still use the existing api for short running commands
let directoryContents = try! shellOut("ls")
print(directoryContents)
Async + streaming shellOutAsync
enum StreamingOutput {
case text: String
case errorText: String
case completed:(Bool) // This could be a throwing function that returns a Bool, or a throwing function that returns all the text
}
public func shellOutAsync(to command: String,
arguments: [String] = [],
at path: String = ".",
withOutput output: @escaping (StreamingOutput) -> Void) {}
shellOutAsync("docker compose .") { output in
switch output {
case .text, .errorText(let text)
print(text)
case .completed(let success)
if (success) { // run next command }
}
}
}
Does anyone have an example of when they would use the async version?
from shellout.
@iainsmith example of when I would use the async version: I'm doing a long-running pod repo push
invocation to automate updating the pod specs for some proprietary frameworks. The curl + compile takes ~1 minute, so it is helpful to get the visual output to confirm things are working correctly. Absent the expected log messages, I would need to just observer the header of Terminal, to see which command is currently executing.
from shellout.
Closing as I’ve now migrated to swift-tools-core.
from shellout.
Related Issues (20)
- ShellOut "swift package update" not working in some scenarios
- Running shellOut on concurrentPerform
- FileHandle crash if you run multiple shellout calls HOT 2
- ShellOut make error?
- Cannot build SwiftUI preview HOT 2
- dynamic library
- Change shell from bash to zsh HOT 2
- Add Compatibility with Commands like "vi" HOT 4
- I get an error when I execute the pod command
- ShellOut without Marathon
- /bin/bash: pod: command not found HOT 2
- How to access ssh key
- How do I install ShellOut to Xcode? HOT 1
- /bin/bash: pod: command not found HOT 1
- Uncaught NSRangeException on waitUntilExit()
- Cannot find type 'Process' in scope HOT 10
- run‘xcodebuild build’surprisingly slow!Can help me?
- Standard output delay
- How to properly open a terminal editor?
- NSInternalInconsistencyException occurs when shellOut is run too many times
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shellout.