Skip to content

Commit

Permalink
feat: output version when run in verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy McKay committed May 10, 2016
1 parent 4c4d09d commit e4280dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class Program {
return this;
}

run({throwError=false, systemProcess=process, logStream=defaultLogStream}
run(absolutePackageDir: string,
{throwError=false, systemProcess=process, logStream=defaultLogStream,
getVersion=version}
: Object = {}): Promise {
let argv = this.yargs.argv;
let cmd = argv._[0];
Expand All @@ -65,6 +67,7 @@ export class Program {
throw new WebExtError(`unknown command: ${cmd}`);
}
if (argv.verbose) {
log.info('Version:', getVersion(absolutePackageDir));
logStream.makeVerbose();
}
resolve(runCommand);
Expand Down Expand Up @@ -195,5 +198,5 @@ Example: $0 --help run.
},
});

return program.run(runOptions);
return program.run(absolutePackageDir, runOptions);
}
22 changes: 17 additions & 5 deletions tests/test.program.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ describe('program.Program', () => {

function run(program, options={}) {
let fakeProcess = fake(process);
return program.run({
systemProcess: fakeProcess,
throwError: true,
...options,
});
let absolutePackageDir = path.join(__dirname, '..');
return program.run(
absolutePackageDir, {
systemProcess: fakeProcess,
throwError: true,
...options,
});
}

it('executes a command callback', () => {
Expand Down Expand Up @@ -139,6 +141,16 @@ describe('program.Program', () => {
});
});

it('checks the version when verbose', () => {
let version = spy();
let program = new Program(['thing', '--verbose'])
.command('thing', 'does a thing', () => {});
return run(program, {getVersion: version})
.then(() => {
assert.equal(version.firstCall.args[0], path.join(__dirname, '..'));
});
});

it('does not configure the logger unless verbose', () => {
const logStream = fake(new ConsoleStream());
let program = new Program(['thing']).command('thing', '', () => {});
Expand Down

0 comments on commit e4280dd

Please sign in to comment.