So I'm using inquirer to ask a question from my users via terminal:
var inquirer = require('inquirer');
var question = {
  name: 'name',
  message: '',
  validation: function(){ ... }
  filter: function(){ ... }
};
but at the same time let my users pass this field via --name command line argument. (say arg.name)
Question is: How can I tell inquirer to take this arg.name value and use it as if user entered it for the answer of this question.
Note that I DO need the validation and filter to also kick-in for this value. (for example if value passed via --name is invalid, the user is presented with the error message and asked to enter another value)
I'm hoping there is a way to solve this problem without having to hack-around manually calling my validation/filter methods.
You could set up a default value to a variable from arg.name:
let argument = args.name;        
const question = {
  name: 'name',
  message: 'Name?',
  default: argument
};
I tried testing this and it works. The user just has to hit enter to use the name passed in the arguments so maybe tell them that in the prompt. Also be aware that your validation will take place AFTER your filters. You just need to make sure whatever your filters are doing will pass validation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With