Swiftpack.co - Einstore/ShellKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Einstore.
Einstore/ShellKit 1.6.0
Access local shell as well as remote over SSH
⭐️ 18
🕓 4 years ago
.package(url: "https://github.com/Einstore/ShellKit.git", from: "1.6.0")

ShellKit

Access local shell as well as remote over SSH for Swift NIO applications

Install using SPM

.package(url: "https://github.com/Einstore/ShellKit.git", from: "1.0.0")

Usage

Connect to a local terminal

let shell = try Shell(.local, on: eventLoop)
let futureResponse = shell.run(bash: "ls -a").map { output in
   print(output)
   return output
}

Connect to a remote service

let shell = try Shell(
    .ssh(
        host: "1292.168.1.2",
        username: "root",
        password: "sup3rS3cr3t"
    ),
    on: eventLoop
)
let futureResponse = shell.run(bash: "ls -a")

Other means of SSH authentication are available!

Example

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)

Using CommandKit

Access commands through

Example:

shell.cmd.pwd().map { currentPath in
   print(currentPath)
}

Discover more commands under shell.cmd and shell.cmd.install

Author

Ondrej Rafaj @rafiki270

License

MIT; Copyright 2019 - Einstore

GitHub

link
Stars: 18
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.6.0
4 years ago
  • Mocking capability

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics