inquirer#Question TypeScript Examples

The following examples show how to use inquirer#Question. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From backstage with Apache License 2.0 5 votes vote down vote up
async function verifyGithubOrg(org: string): Promise<void> {
  let response;

  try {
    response = await fetch(
      `https://api.github.com/orgs/${encodeURIComponent(org)}`,
    );
  } catch (e) {
    console.log(
      chalk.yellow(
        'Warning: Unable to verify existence of GitHub organization. ',
        e,
      ),
    );
  }

  if (response?.status === 404) {
    const questions: Question[] = [
      {
        type: 'confirm',
        name: 'shouldCreateOrg',
        message: `GitHub organization ${chalk.cyan(
          org,
        )} does not exist. Would you like to create a new Organization instead?`,
      },
    ];

    const answers = await inquirer.prompt(questions);

    if (!answers.shouldCreateOrg) {
      console.log(
        chalk.yellow('GitHub organization must exist to create GitHub app'),
      );
      process.exit(1);
    }

    openBrowser('https://github.com/account/organizations/new');

    console.log(
      chalk.yellow(
        'Please re-run this command when you have created your new organization',
      ),
    );

    process.exit(0);
  }
}
Example #2
Source File: prompt.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
answerRequired = (question: QuestionWithValidation): Question<any> => {
  return {
    ...question,
    validate: (answer: any) => answer.trim() !== '' || `${question.name} is required`,
  };
}