为 Swift NIO 应用程序提供访问本地 Shell 和通过 SSH 访问远程 Shell 的能力
.package(url: "https://github.com/Einstore/ShellKit.git", from: "1.0.0")
let shell = try Shell(.local, on: eventLoop)
let futureResponse = shell.run(bash: "ls -a").map { output in
print(output)
return output
}
let shell = try Shell(
.ssh(
host: "1292.168.1.2",
username: "root",
password: "sup3rS3cr3t"
),
on: eventLoop
)
let futureResponse = shell.run(bash: "ls -a")
还有其他 SSH 身份验证方式可用!
let eventLoop = EmbeddedEventLoop()
let shell = try Shell(.local, on: eventLoop)
let futureResponse = shell.run(bash: "cd /tmp/ ; pwd").map { output in
print(output)
return output
}.flatMapError { error in
print(error)
return error.localizedDescription
}
let out: String = try futureResponse.wait()
print(out)
通过以下方式访问命令
示例
shell.cmd.pwd().map { currentPath in
print(currentPath)
}
在
shell.cmd
和shell.cmd.install
下发现更多命令
Ondrej Rafaj @rafiki270
MIT;版权所有 2019 - Einstore