Skip to content

pompt.override can't handle nested prompts #47

Open
davidpfahler opened this Issue Aug 17, 2012 · 1 comment

2 participants

@davidpfahler

It's already in the source code as a comment, but I wanted to track it here.

@tkdan235

I can confirm this issue. Below is the test code:

//prompt-override.js

var prompt = require('prompt'),
    optimist = require('optimist');

var config = {}

//prompt-override.js
//
// set the overrides
//
prompt.override = optimist.argv

//
// Start the prompt
//
prompt.start();


 console.log('Initial object to be extended:');
  console.dir(config);
//
// Get two properties from the user: username and password
//
prompt.addProperties(config, [{
      name: 'username',
      default: 'bar'
    }, {
      name: 'password',
      default: 'foo',
      conform: function (value) {
        return true;
      }
    }], function(err, result) {
    //
    // Log the results.
    //
    console.log('Command-line input received:');
    console.log('  username: ' + result.username);
    console.log('  password: ' + result.password);

    console.log('Updated object received:');
    console.dir(config);
})

And here is my output when I do not add any arguments (I am expecting the default validation to kick in automatically without prompting me):

$ node test.js
Initial object to be extended:
{}
prompt: username:  (bar) 
prompt: password:  (foo) 
Command-line input received:
  username: bar
  password: foo
Updated object received:
{ username: 'bar', password: 'foo' }

With arguments it works as expected:

$ node test.js --username foo --password bar
Initial object to be extended:
{}
Command-line input received:
  username: foo
  password: bar
Updated object received:
{ username: 'foo', password: 'bar' }

Notice in the second example the following is not prompted:

prompt: username:  (bar) 
prompt: password:  (foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.