Skip to content

Commit

Permalink
Improved log fomatting in question command
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsofapollo committed Mar 18, 2012
1 parent 40e667e commit 0f70330
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
12 changes: 9 additions & 3 deletions example/generator-example/run.js
Expand Up @@ -9,9 +9,15 @@ var Generator = require('file-generator'),

generator.template('package.json');

variables.
set('package.name', 'myPackage').
set('package.version', '1.0');
generator.question('package.name', {
prompt: "What is the name of your package? "
});

generator.question('package.version', {
prompt: "What is the version for your package? ",
defaultValue: '0.0.1'
});


generator.run(function(){
console.log('Complete');
Expand Down
19 changes: 18 additions & 1 deletion lib/commands/question.js
@@ -1,11 +1,27 @@
var QuestionLib = require('../question');

function Question(variable, config, gen){
var question;

if(typeof(config) === 'undefined'){
config = {};
}

this.gen = gen;
this.variable = variable;
this.question = new QuestionLib(config);

question = this.question = new QuestionLib(config);

if(question.prompt){
question.prompt = this.gen.logFormat(
this.logPrefix + variable, question.prompt
);
}
}


Question.prototype.logPrefix = 'variable: ';

/**
* Does not do anything just for api compat with
* other commands.
Expand All @@ -29,6 +45,7 @@ Question.prototype.check = function(callback){
*/
Question.prototype.execute = function(callback){
var self = this;

this.question.run(function(value){
self.gen.variables.set(
self.variable,
Expand Down
10 changes: 9 additions & 1 deletion spec/commands/question-spec.js
Expand Up @@ -28,7 +28,15 @@ describe("command/question", function(){

it("should set .question", function(){
expect(subject.question).to.be.a(Question);
expect(subject.question.prompt).to.be('foo? ');
});

it("should pass .question.prompt through log formatter", function(){

var keyName = subject.logPrefix + subject.variable;

expect(subject.question.prompt).to.equal(
generator.logFormat(keyName, 'foo? ')
);
});

});
Expand Down

0 comments on commit 0f70330

Please sign in to comment.