https://github.com/rumkin/local-shell
Local shell client implementation
https://github.com/rumkin/local-shell
Last synced: about 2 months ago
JSON representation
Local shell client implementation
- Host: GitHub
- URL: https://github.com/rumkin/local-shell
- Owner: rumkin
- Created: 2016-06-10T12:37:25.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-10T13:19:09.000Z (about 10 years ago)
- Last Synced: 2025-09-27T14:56:11.447Z (9 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Local Shell
Local shell is a util to manage shell commands in asynchronous way like it's
executed remotely. It has the same interface as Ssh-Shell to simplify usage.
## Installation
Install via npm
```
npm i local-shell
```
## Example
Example of variable usage:
```javascript
const LocalShell = require('local-shell');
const fs = require('fs');
const shell = new LocalShell({
cwd: process.cwd(),
});
shell.set('NAME', 'World');
shell.exec('echo Hello $NAME')
.then(result => {
var {code, io} = result;
if (code) {
throw new Error('Exit code is ' + code);
}
console.log(io.toString()); // -> Hello World
});
```
## API
### exec(cmd:String) -> Promise<{code,io},Error>
Execute command and return promised Result object.
### open()
_Added for compatibility with SshShell_
Start session. Emit `open` event.
### close()
_Added for compatibility with SshShell_
Stop session. Emit `close` event.
### uploadFile(source:String, [dest:String]) -> Promise()
Upload file from source to destination. Destination is resolving from `cwd` value. If destination not set than it replaces with source's filename.
### uploadBuffer(source:Buffer, dest:string) -> Promise()
Upload data from buffer to the server.
### downloadFile(source:String, [dest:String])
Download file from source into destination. If destination not set than it replaces with source's filename.