@@ -10,7 +10,7 @@ import { log } from "./logger"
1010import { MassargCommand } from "massarg/command"
1111import { getUniqueTmpPath as generateUniqueTmpPath } from "./file"
1212import { colorize } from "./colors"
13- import { promptForMissingConfig , resolveInputs } from "./prompts"
13+ import { promptBeforeConfig , promptAfterConfig , resolveInputs } from "./prompts"
1414import { initScaffold } from "./init"
1515
1616export async function parseCliArgs ( args = process . argv . slice ( 2 ) ) {
@@ -33,8 +33,10 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
3333 log ( config , LogLevel . debug , `Simple Scaffold v${ pkg . version } ` )
3434 config . tmpDir = generateUniqueTmpPath ( )
3535 try {
36- // Auto-detect config file in cwd if not explicitly provided
37- if ( ! config . config && ! config . git ) {
36+ // Auto-detect config file in cwd — but only if the user didn't
37+ // explicitly provide templates/output (which signals a one-time run)
38+ const isOneTimeRun = config . templates ?. length > 0 || config . output
39+ if ( ! config . config && ! config . git && ! isOneTimeRun ) {
3840 try {
3941 config . config = await findConfigFile ( process . cwd ( ) )
4042 log ( config , LogLevel . debug , `Auto-detected config file: ${ config . config } ` )
@@ -43,19 +45,24 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
4345 }
4446 }
4547
46- // Load config early so we can prompt for template key
48+ // Load config map early so we can prompt for name and template key
4749 const hasConfigSource = Boolean ( config . config || config . git )
4850 let configMap : ScaffoldConfigMap | undefined
4951 if ( hasConfigSource ) {
5052 configMap = await getConfigFile ( config )
5153 }
5254
53- // Prompt for missing values interactively
54- config = await promptForMissingConfig ( config , configMap )
55+ // Phase 1: prompt for name + key (needed before parseConfigFile)
56+ config = await promptBeforeConfig ( config , configMap )
5557
58+ // Parse and merge the config file
5659 log ( config , LogLevel . debug , "Parsing config file..." , config )
5760 const parsed = await parseConfigFile ( config )
58- const resolved = await resolveInputs ( parsed )
61+
62+ // Phase 2: prompt for anything still missing after config merge
63+ const prompted = await promptAfterConfig ( parsed )
64+
65+ const resolved = await resolveInputs ( prompted )
5966 await Scaffold ( resolved )
6067 } catch ( e ) {
6168 const message = "message" in ( e as object ) ? ( e as Error ) . message : e ?. toString ( )
0 commit comments