-
-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Generate command prompts for values that are already provided via CLI flags
Information
- Version: 6.6.3
- Packages: @tsed/cli
The generate command incorrectly prompts for values that are already provided via command-line flags. When passing options like --route, --directory, etc., the CLI still prompts for these values instead of using what was provided.
Example
# This command provides the route via --route flag
tsed g --route="api/receipts" "Controller" "Receipts"
# But still prompts:
? Which route? (/receipts)Even though the data object clearly contains the route:
{
verbose: false,
type: 'Controller',
name: 'Receipts',
route: 'api/receipts', // β Route is provided
rawArgs: []
}
? Which route? (/receipts) // β But still promptsRoot Cause
The when conditions in the prompt definitions have inverted logic. They show prompts when values exist instead of when they're missing.
Current broken code:
{
type: "input",
name: "route",
message: "Which route?",
when(state) {
// This returns true (shows prompt) when route EXISTS
return !!(["controller", "server"].includes(state.type || initialOptions.type) || initialOptions.route);
},
...
}The || initialOptions.route causes the prompt to show when route exists, which is backwards.
Affected Prompts
All prompts with this pattern are affected:
route- prompts even when--routeis provideddirectory- prompts even when--directoryis providedtemplateType- prompts even when--templateTypeis providedmiddlewarePosition- prompts even when--middlewarePositionis provided
Solution
The when conditions need to check for the absence of values, not their presence:
{
type: "input",
name: "route",
message: "Which route?",
when(state) {
// Only show prompt when route is NOT provided
return !initialOptions.route && ["controller", "server"].includes((state.type || initialOptions.type).toLowerCase());
},
default: (state) => {
return state.type === "server" ? "/rest" : this.routePipe.transform(getName(state));
}
},
{
type: "list",
name: "directory",
message: "Which directory?",
when(state) {
// Only show prompt when directory is NOT provided
return ["controller"].includes((state.type || initialOptions.type).toLowerCase()) && !initialOptions.directory;
},
choices: this.getDirectories("controllers")
},
// Similar fixes needed for templateType and middlewarePosition promptsNote: Added .toLowerCase() to handle case-insensitive type matching ('Controller' vs 'controller').
Acceptance criteria
- Prompts should only appear when values are NOT provided via CLI flags
- When
--routeis provided, the route prompt should be skipped - When
--directoryis provided, the directory prompt should be skipped - When other options are provided via flags, their respective prompts should be skipped
- Type comparisons should be case-insensitive