import ShellClient
func echo() throws {
@Dependency(\.logger) var logger
@Dependency(\.shellClient) var shell
try shell.foreground(["echo", "Foo"])
// Or run in a background process, and capture the output.
let output = try shell.background(
["echo", "world"]
trimmingCharactersIn: .whitespacesAndNewlines
)
logger.info("Hello \(output)!")
}
func echoAsync() async throws {
@Dependency(\.logger) var logger
@Dependency(\.asyncShellClient) var shell
try await shell.foreground(["echo", "Foo"])
// Or run in a background process, and capture the output.
let output = try await shell.background(
["echo", "world"],
trimmingCharactersIn: .whitespacesAndNewlines
)
logger.info("Hello \(output)!")
}
try echo()
try await echoAsync()
Logging
We use swift-log along with
swift-log-format-and-pipe to create
a basic logger that you have access to. You can also use
Rainbow for color text output to the terminal.
The built-in logger will just log messages without any label when built in release and will
log with the label shell-client when in debug or testing context.
You can create a basic logger with a label by using the following method provided by the
library.
swift-shell-client
A package that allows you to run shell scripts from your swift code.
Github Repository Documentation
Usage
You can include in your project, by using swift package manager.
Basic Usage
You access a shell client through the swift-dependencies system.
Logging
We use swift-log along with swift-log-format-and-pipe to create a basic logger that you have access to. You can also use Rainbow for color text output to the terminal.
The built-in logger will just log messages without any label when built in release and will log with the label
shell-client
when in debug or testing context.You can create a basic logger with a label by using the following method provided by the library.
Documentation
You can read the full documentation here.