Closed drewbrokke closed 8 years ago
Otherwise, LGTM! :+1:
👍 this will also allow for fall through to the parent shell, eg
const vorpal = require('vorpal')();
const spawn = require('child_process').spawn;
vorpal
.catch('[words...]', 'Catches incorrect commands')
.allowUnknownOptions()
.action(function (args, cb) {
// need to have a better reduce to split the args appropriately when they have params
const options = Object.keys(args.options).map((option) => '-'+option);
const cmd = spawn(args.words.shift(), args.words.concat(options));
cmd.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
cmd.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
cmd.on('close', (code) => {
this.log(`child process exited with code ${code}`);
cb();
});
});
So when in a shell a user could run
myshell~$ ls -la
stdout: total 64
drwxr-xr-x 13 zak staff 442 Jun 6 10:26 .
drwxr-xr-x 8 zak staff 272 May 29 13:37 ..
drwxr-xr-x 16 zak staff 544 Jun 6 10:41 .git
-rw-r--r-- 1 zak staff 179 May 26 10:38 .gitignore
drwxr-xr-x 12 zak staff 408 May 25 18:47 .idea
drwxr-xr-x 3 zak staff 102 May 25 12:06 bin
drwxr-xr-x 9 zak staff 306 May 26 12:20 browser
drwxr-xr-x 6 zak staff 204 Jun 2 17:09 docs
-rw-r--r-- 1 zak staff 80 May 25 12:54 index.js
drwxr-xr-x 903 zak staff 30702 Jun 6 09:59 node_modules
-rw-r--r-- 1 zak staff 3368 Jun 6 09:59 package.json
drwxr-xr-x 3 zak staff 102 May 25 16:55 server
-rw-r--r-- 1 zak staff 18203 Jun 3 14:45 tasks.js
child process exited with code 0
Unless there is an easier way to achieve this fallback on the parent shell?
@dthree I have updated the branch with the changes you suggested. Please let me know if you have any questions :)
Thanks, looks great!!
@drewbrokke I'll review this ASAP. Thanks for the PR.