How to use the inquirer.direct function in inquirer

To help you get started, we’ve selected a few inquirer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kuzzleio / kuzzle / bin / .upgrades / lib / inquirerExtended.js View on Github external
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Returns an instance of "inquirer" extended with a "direct" function that
// returns the answer directly, instead of a key-value map of answers.
// Useful only because we often prompt questions one by one, with tasks in the
// middle, and this "direct" function helps reducing the clutter.

const
  assert = require('assert').strict,
  inquirer = require('inquirer'),
  _ = require('lodash');

inquirer.direct = async function direct (prompt) {
  assert(_.isPlainObject(prompt), 'Invalid argument: expected a non-empty object');
  assert(typeof prompt.name === 'undefined', 'Unexpected "name" argument: if you need to set a name, use inquirer.prompt');

  const p = _.cloneDeep(prompt);
  p.name = 'foo';

  const { foo } = await inquirer.prompt(p);

  return foo;
};

module.exports = inquirer;