dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Errors in actions are hidden #20

Closed DavertMik closed 9 years ago

DavertMik commented 9 years ago

Can't trace errors while running commands in non-interactive shell

@dthree

Figured it out. .exec was intended to be programmatic, so it eats teh error and returns it in exec's callback. .parse calls .exec, so it eats the error when invoked through .parse, but not otherwise.

#!/usr/bin/env node

var program = require('vorpal')();
var path = require('path');
var fs = require('fs');
var colors = require('colors');

var error = colors.bgRed.white.bold;

program.command('init [path]')
  .description('Creates dummy config in current dir or [path]')
  .action((args) => {
    var path = args.path || '';
    var configFile = path.join(process.cwd(), path, 'codecept.json');
    this.log(path);
    try {
      fs.writeFileSync(configFile, '{}')
    } catch (err) {
      this.log(error(`File can't be created at ${configFile}`));
      program.exit();
    }
    this.log(`Config created at ${configFile}`);
  });

program.parse(process.argv);
dthree commented 9 years ago

Should be a fast fix.

dthree commented 9 years ago

Fixed.