How to use enquirer - 10 common examples

To help you get started, we’ve selected a few enquirer 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 node-modules / coffee / test / fixtures / prompt-enquirer.js View on Github external
#!/usr/bin/env node

'use strict';

const { prompt } = require('enquirer');
const { ReadStream } = require('tty');

prompt.on('prompt', prompt => {
  // console.log(prompt);
  process.send && process.send({ type: 'prompt' });
});

async function run() {
  const stdin = new ReadStream(process.stdin.fd);
  process.stdin.pipe(stdin);
  const answers = await prompt([
    {
      type: 'input',
      name: 'name',
      message: 'What is your name?',
      stdin,
    },
    {
      type: 'select',
github saasify-sh / saasify / packages / saasify-cli / lib / commands / remove.js View on Github external
const invalidLabel = pluralize('deployment', invalid.length)
          console.error(`Error invalid ${invalidLabel} [${invalid.join(', ')}]`)
          process.exit(1)
        }

        // TODO: if any projects are specified without deployment version info, then
        // expand them out to include all deployments in those projects

        // TODO: currently if you specify a project, it'll do project@latest...

        const deployments = parsedArgs.map(({ deploymentId }) => deploymentId)

        if (!opts.yes) {
          console.error(`${deploymentsLabel}:`, deployments.join(', '))

          const prompt = new Confirm({
            message: `Are you sure you want to delete these ${deployments.length} ${deploymentsLabel}?`,
            initial: true
          })

          const answer = await prompt.run()
          if (!answer) {
            process.exit(1)
          }
        }

        await spinner(
          pMap(
            deployments,
            (deploymentId) => {
              return client.removeDeployment(deploymentId, {
                safe: opts.safe
github saasify-sh / saasify / packages / saasify-cli / lib / commands / unsubscribe.js View on Github external
throw new Error(`Invalid project identifier [${identifier}]`)
        }

        const { projectId } = parsedFaas

        // TODO: remove this call to resolveConsumers?
        // TODO: is moving all parsing and ID formatting logic to be shared between
        // client and server really a good idea?

        const consumer = await spinner(
          client.getConsumerByProject(projectId),
          `Resolving subscription for project [${projectId}]`
        )

        if (!opts.yes) {
          const prompt = new Confirm({
            message: `Are you sure you want to unsubscribe from project [${consumer.project}]?`,
            initial: true
          })

          const answer = await prompt.run()
          if (!answer) {
            process.exit(1)
          }
        }

        await spinner(
          client.removeConsumer(consumer),
          `Cancelling subscription to project [${consumer.project}]`
        )

        program.appendOutput(
github sw-yx / ssg / packages / ssg / src / eject.ts View on Github external
async function eject([_sourceFile, destinationPath]: string[]) {
  const sourceFile = path.resolve(
    __dirname,
    '../ejectableFiles/' + _sourceFile
  );
  debug(`ejecting: from ${_sourceFile} to ${destinationPath}`);
  if (fs.existsSync(sourceFile)) {
    try {
      ensureDirectoryExistence(destinationPath);
      if (fs.existsSync(destinationPath)) {
        const prompt = new Confirm({
          name: 'question',
          message: `A file exists at ${chalk.cyan(
            destinationPath
          )}. Are you sure you want to overwrite?`
        });
        const answer = await prompt.run();
        if (!answer) return; // dont override
        try {
          fs.renameSync(destinationPath, destinationPath + '.old');
        } catch (err) {
          console.log('renaming failed. copying and overwriting instead.');
          fs.copyFileSync(destinationPath, destinationPath + '.copy');
        }
      }
      fs.copyFileSync(sourceFile, destinationPath);
      console.log(
github enquirer / enquirer / examples / number / option-format.js View on Github external
'use strict';

const { NumberPrompt } = require('enquirer');
const placeholder = require('../../lib/placeholder');

const prompt = new NumberPrompt({
  name: 'amount',
  message: 'How much do you want to donate?',
  float: true,
  cursor: 1,
  format(input = this.input) {
    const str = Intl.NumberFormat(void 0, { style: 'currency', currency: 'USD' }).format(input);

    let pos = this.cursor + 1;

    // Total number of commas (,) in the formatted string
    const totalcommas = str.split(',').length - 1;

    // Number of commas (,) to the right of the current cursor position
    const extracommas =
      Intl.NumberFormat(void 0, { style: 'currency', currency: 'USD' })
        .format(
github enquirer / enquirer / examples / numeral / option-format.js View on Github external
'use strict';

const { NumberPrompt } = require('enquirer');
const placeholder = require('../../lib/placeholder');

const prompt = new NumberPrompt({
  name: 'amount',
  message: 'How much do you want to donate?',
  float: true,
  format(input = this.input) {
    const str = Intl.NumberFormat(void 0, { style: 'currency', currency: 'USD' }).format(input);

    let pos = this.cursor + 1;

    // Total number of commas (,) in the formatted string
    const totalcommas = str.split(',').length - 1;

    // Number of commas (,) to the right of the current cursor position
    const extracommas =
      Intl.NumberFormat(void 0, { style: 'currency', currency: 'USD' })
        .format(
          input
github satyarohith / shark / src / prompts / projects.js View on Github external
const {prompt} = require('enquirer');

// Check https://github.com/enquirer/enquirer/issues/13#issuecomment-447602031
prompt.on('cancel', () => process.exit());

/**
 * @param {string} name - The name of the project
 * @param {string} description - The description of the project
 * @param {string} purpose - The purpose of the project
 * @param {string} environment - The environment of the project's resources
 * @returns {Promise} prompt - Returns a prompt
 */
const askProjectDetails = (name, description, purpose, environment) => {
  return prompt({
    type: 'form',
    name: 'project',
    message: 'Enter the missing values:',
    choices: [
      {name: 'name', value: 'Name', initial: name},
      {
github satyarohith / shark / src / prompts / droplets.js View on Github external
const {prompt} = require('enquirer');

// Check https://github.com/enquirer/enquirer/issues/13#issuecomment-447602031
prompt.on('cancel', () => process.exit());

/**
 * @param  {Array} sizes - Available droplet sizes
 * @returns {Promise} prompt - Returns a prompt
 */
const askDropletSize = sizes =>
  prompt({
    type: 'select',
    name: 'dropletSize',
    message: 'Select droplet size',
    choices: sizes
  });

const askDropletImage = images => {
  return prompt({
    type: 'autocomplete',
github satyarohith / shark / src / prompts / records.js View on Github external
const {prompt} = require('enquirer');

// Check https://github.com/enquirer/enquirer/issues/13#issuecomment-447602031
prompt.on('cancel', () => process.exit());

const askRecordID = records => {
  return prompt({
    type: 'select',
    name: 'recordID',
    choices: records
  });
};

const askRecordType = () => {
  return prompt({
    type: 'select',
    message: 'Select record type',
    name: 'recordType',
    choices: ['A', 'AAAA', 'CNAME', 'TXT', 'NS', 'MX', 'SRV']
  });
github satyarohith / shark / src / prompts / index.js View on Github external
const {prompt} = require('enquirer');

// Check https://github.com/enquirer/enquirer/issues/13#issuecomment-447602031
prompt.on('cancel', () => process.exit());

const askToken = () => {
  return prompt({
    type: 'input',
    name: 'token',
    message: 'What is your token?'
  });
};

const askDomainName = () => {
  return prompt({
    type: 'input',
    name: 'domainName',
    message: 'Enter your domain name:'
  });
};