How to use the enquirer.Sort function in enquirer

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 aws-amplify / amplify-cli / packages / amplify-category-auth / provider-utils / awscloudformation / service-walkthroughs / auth-questions.js View on Github external
name: 'repeater',
      type: 'confirm',
      default: false,
      message: 'Do you want to add another User Pool Group',
    });
  }

  // Get distinct list
  const distinctSet = new Set(userPoolGroupList);
  userPoolGroupList = Array.from(distinctSet);

  // Sort the Array to get precedence
  let sortedUserPoolGroupList = [];

  if (userPoolGroupList && userPoolGroupList.length > 0) {
    const sortPrompt = new Sort({
      name: 'sortUserPools',
      hint: `(Use ${chalk.green.bold('+')} to change the order)`,
      message: 'Sort the user pool groups in order of preference',
      choices: userPoolGroupList,
      shiftLeft(...args) {
        return this.shiftUp(...args);
      },
      shiftRight(...args) {
        return this.shiftDown(...args);
      },
    });

    sortedUserPoolGroupList = await sortPrompt.run();
  }
  return sortedUserPoolGroupList;
}
github enquirer / enquirer / examples / sort / prompt-ranking.js View on Github external
'use strict';

const { Sort } = require('enquirer');

const prompt = new Sort({
  name: 'career',
  message: 'Please rank the following in order of importance',
  numbered: true,
  choices: ['Recognition', 'Opportunity', 'Pay', 'Benefits', 'Co-workers']
});

prompt.run()
  .catch(console.error);
github enquirer / enquirer / examples / sort / prompt.js View on Github external
'use strict';

const colors = require('ansi-colors');
const { Sort } = require('enquirer');
const prompt = new Sort({
  name: 'colors',
  message: 'Sort the colors in order of preference',
  hint: 'Top is best, bottom is worst',
  numbered: true,
  choices: ['red', 'white', 'green', 'cyan', 'yellow'].map(n => ({
    name: n,
    message: colors[n](n)
  }))
});

prompt.run()
  .then(function(answer = []) {
    console.log(answer);
    console.log('Your preferred order of colors is:');
    console.log(answer.map(key => colors[key](key)).join('\n'));
  })