Comparing version
@@ -34,3 +34,3 @@ import chalk from "chalk"; | ||
type: inputType, | ||
name: option.long.replace("--", ""), | ||
name: camelize(option.long.replace("--", "")), | ||
message: option.description, | ||
@@ -41,14 +41,9 @@ choices: hasChoices ? convertStringToOptions(option.flags) : undefined, | ||
export async function autoprompt(program, autoPromptOpts) { | ||
const options = program.options.map(validateOption); | ||
program.parseOptions(process.argv); | ||
const parsedOptions = program.opts(); | ||
const promptedOptions = await promptForMissingOptions(autoPromptOpts?.prompter ?? prompt, options, parsedOptions); | ||
const args = process.argv; | ||
args.push(...Object.entries(promptedOptions) | ||
.filter(([_key, value]) => value != null) | ||
.map(([key, value]) => { | ||
return `--${key}=${value}`; | ||
})); | ||
program.parse(args); | ||
return program; | ||
program.hook("preAction", async (_rootCommand, subCommand) => { | ||
const options = subCommand.options.map(validateOption); | ||
// subCommand.parseOptions(); | ||
const promptedOptions = await promptForMissingOptions(autoPromptOpts?.prompter ?? prompt, options, subCommand.opts()); | ||
Object.assign(subCommand.opts(), promptedOptions); | ||
}); | ||
return program.parseAsync(); | ||
} | ||
@@ -58,2 +53,5 @@ export async function promptForMissingOptions(prompter, options, parsedOptions) { | ||
.filter((opt) => { | ||
if (opt.flags.includes("(optional)")) { | ||
return false; | ||
} | ||
// only prompt for options that were not passed in | ||
@@ -60,0 +58,0 @@ const missingValue = !parsedOptions[camelize(opt.long.replace("--", ""))]; |
{ | ||
"name": "autoprompt", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13383
-1.14%101
-1.94%