Skip to content

Commit

Permalink
Refactor inquirer to new package structure. Closes pnp#5510
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlingstuyl authored and Adam-it committed Nov 8, 2023
1 parent 0642f3a commit e452b8e
Show file tree
Hide file tree
Showing 312 changed files with 3,244 additions and 4,367 deletions.
448 changes: 262 additions & 186 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@
"dependencies": {
"@azure/msal-common": "^13.2.1",
"@azure/msal-node": "^1.18.3",
"@inquirer/confirm": "^2.0.12",
"@inquirer/input": "^1.2.11",
"@inquirer/select": "^1.2.11",
"@xmldom/xmldom": "^0.8.10",
"adaptive-expressions": "^4.20.1",
"adaptivecards": "^3.0.1",
Expand All @@ -257,7 +260,6 @@
"configstore": "^6.0.0",
"csv-stringify": "^6.4.4",
"easy-table": "^1.2.0",
"inquirer": "^9.2.11",
"jmespath": "^0.16.0",
"json-to-ast": "^2.1.0",
"minimist": "^1.2.8",
Expand All @@ -275,7 +277,6 @@
"devDependencies": {
"@microsoft/microsoft-graph-types": "^2.38.0",
"@types/adm-zip": "^0.5.2",
"@types/inquirer": "^9.0.4",
"@types/jmespath": "^0.15.0",
"@types/json-to-ast": "^2.1.2",
"@types/minimist": "^1.2.3",
Expand Down
32 changes: 7 additions & 25 deletions src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,9 @@ export default abstract class Command {
Cli.error('🌶️ Provide values for the following parameters:');
}

const missingRequireOptionValue = await prompt.forInput<{ missingRequireOptionValue: string }>({
name: 'missingRequireOptionValue',
message: `${command.options[i].name}: `
}).then(result => result.missingRequireOptionValue);
const answer = await prompt.forInput({ message: `${command.options[i].name}: ` });

args.options[command.options[i].name] = missingRequireOptionValue;
args.options[command.options[i].name] = answer;
}

if (prompted) {
Expand Down Expand Up @@ -221,34 +218,19 @@ export default abstract class Command {
private async promptForOptionSetNameAndValue(args: CommandArgs, optionSet: OptionSet): Promise<void> {
Cli.error(`🌶️ Please specify one of the following options:`);

const resultOptionName = await prompt.forInput<{ missingRequiredOptionName: string }>({
type: 'list',
name: 'missingRequiredOptionName',
message: `Option to use:`,
choices: optionSet.options
});
const missingRequiredOptionName = resultOptionName.missingRequiredOptionName;

const resultOptionValue = await prompt.forInput<{ missingRequiredOptionValue: string }>({
name: 'missingRequiredOptionValue',
message: `${missingRequiredOptionName}:`
});
const selectedOptionName = await prompt.forSelection<string>({ message: `Option to use:`, choices: optionSet.options.map((choice: any) => { return { name: choice, value: choice }; }) });
const optionValue = await prompt.forInput({ message: `${selectedOptionName}:` });

args.options[missingRequiredOptionName] = resultOptionValue.missingRequiredOptionValue;
args.options[selectedOptionName] = optionValue;
Cli.error('');
}

private async promptForSpecificOption(args: CommandArgs, commonOptions: string[]): Promise<void> {
Cli.error(`🌶️ Multiple options for an option set specified. Please specify the correct option that you wish to use.`);

const requiredOptionNameResult = await prompt.forInput<{ missingRequiredOptionName: string }>({
type: 'list',
name: 'missingRequiredOptionName',
message: `Option to use:`,
choices: commonOptions
});
const selectedOptionName = await prompt.forSelection({ message: `Option to use:`, choices: commonOptions.map((choice: any) => { return { name: choice, value: choice }; }) });

commonOptions.filter(y => y !== requiredOptionNameResult.missingRequiredOptionName).map(optionName => args.options[optionName] = undefined);
commonOptions.filter(y => y !== selectedOptionName).map(optionName => args.options[optionName] = undefined);
Cli.error('');
}

Expand Down
Loading

0 comments on commit e452b8e

Please sign in to comment.