Skip to content

Commit

Permalink
#5 added --file option
Browse files Browse the repository at this point in the history
  • Loading branch information
itayw committed Mar 4, 2014
1 parent f6bf4ae commit cda7fb3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bin/joola.io.cli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ program
.option('-u, --username [username]', 'username for login with joola.io')
.option('-p, --password [password]', 'password for login with joola.io')
.option('-a, --apitoken [apitoken]', 'APIToken to use instead of username/password')
.option('-e, --eval [script]', 'javascript to execute and close');
.option('-e, --eval [script]', 'javascript to execute and exit')
.option('-f, --file [filename]', 'javascript file to execute and exit');

program
.command('get')
Expand Down Expand Up @@ -145,6 +146,7 @@ var startCLI = function () {
else
cmd = cmd.replace(')', ',' + inject + ')');

cmd = 'try{' + cmd + '}catch(ex){console.log(ex)}';
eval(cmd);
}
else {
Expand All @@ -165,6 +167,17 @@ var startCLI = function () {
require('repl.history')(_repl, 'joolaio_repl_history');
if (program.eval) {
_repl.eval(program.eval, null, null, function (err, result) {
if (err)
throw err;
console.log(util.inspect(result, {depth: null, colors: true}));
exit();
});
}
if (program.file) {
var fileContents = fs.readFileSync(program.file).toString('utf8');
_repl.eval(fileContents, null, null, function (err, result) {
if (err)
throw err;
console.log(util.inspect(result, {depth: null, colors: true}));
exit();
});
Expand Down

0 comments on commit cda7fb3

Please sign in to comment.