@@ -16,7 +16,7 @@ import { retryWithPrompt } from '../command-helpers/retry.js';
1616import { generateScaffold , writeScaffold } from '../command-helpers/scaffold.js' ;
1717import { sortWithPriority } from '../command-helpers/sort.js' ;
1818import { withSpinner } from '../command-helpers/spinner.js' ;
19- import { getSubgraphBasename } from '../command-helpers/subgraph.js' ;
19+ import { formatSubgraphName , getSubgraphBasename } from '../command-helpers/subgraph.js' ;
2020import { GRAPH_CLI_SHARED_HEADERS } from '../constants.js' ;
2121import debugFactory from '../debug.js' ;
2222import EthereumABI from '../protocols/ethereum/abi.js' ;
@@ -38,8 +38,8 @@ export default class InitCommand extends Command {
3838 static description = 'Creates a new subgraph with basic scaffolding.' ;
3939
4040 static args = {
41- subgraphName : Args . string ( ) ,
42- directory : Args . string ( ) ,
41+ argSubgraphName : Args . string ( ) ,
42+ argDirectory : Args . string ( ) ,
4343 } ;
4444
4545 static flags = {
@@ -116,10 +116,13 @@ export default class InitCommand extends Command {
116116
117117 async run ( ) {
118118 const {
119- args : { subgraphName , directory } ,
119+ args : { argSubgraphName , argDirectory } ,
120120 flags,
121121 } = await this . parse ( InitCommand ) ;
122122
123+ const subgraphName = formatSubgraphName ( argSubgraphName ?? '' ) ;
124+ const directory = argDirectory ?? '' ;
125+
123126 const {
124127 protocol,
125128 node : nodeFlag ,
@@ -343,27 +346,43 @@ async function processFromExampleInitForm(
343346 | undefined
344347> {
345348 try {
346- const { subgraphName } = await prompt . ask < { subgraphName : string } > ( [
347- {
348- type : 'input' ,
349- name : 'subgraphName' ,
350- message : 'Subgraph slug' ,
351- initial : initSubgraphName ,
349+ const promptManager = new PromptManager ( ) ;
350+
351+ let subgraphName = initSubgraphName ;
352+ let directory = initDirectory ;
353+
354+ promptManager . addStep ( {
355+ type : 'input' ,
356+ name : 'subgraphName' ,
357+ message : 'Subgraph slug' ,
358+ initial : initSubgraphName ,
359+ validate : value => formatSubgraphName ( value ) . length > 0 || 'Subgraph slug must not be empty' ,
360+ result : value => {
361+ value = formatSubgraphName ( value ) ;
362+ initDebugger . extend ( 'processFromExampleInitForm' ) ( 'subgraphName: %O' , value ) ;
363+ subgraphName = value ;
364+ return value ;
352365 } ,
353- ] ) ;
354-
355- const { directory } = await prompt . ask < { directory : string } > ( [
356- {
357- type : 'input' ,
358- name : 'directory' ,
359- message : 'Directory to create the subgraph in' ,
360- initial : ( ) => initDirectory || getSubgraphBasename ( subgraphName ) ,
366+ } ) ;
367+
368+ promptManager . addStep ( {
369+ type : 'input' ,
370+ name : 'directory' ,
371+ message : 'Directory to create the subgraph in' ,
372+ initial : ( ) => initDirectory || getSubgraphBasename ( subgraphName ! ) ,
373+ validate : value => value . length > 0 || 'Directory must not be empty' ,
374+ result : value => {
375+ directory = value ;
376+ initDebugger . extend ( 'processFromExampleInitForm' ) ( 'directory: %O' , value ) ;
377+ return value ;
361378 } ,
362- ] ) ;
379+ } ) ;
380+
381+ await promptManager . executeInteractive ( ) ;
363382
364383 return {
365- subgraphName,
366- directory,
384+ subgraphName : subgraphName ! ,
385+ directory : directory ! ,
367386 } ;
368387 } catch ( e ) {
369388 this . error ( e , { exit : 1 } ) ;
@@ -563,8 +582,9 @@ async function processInitForm(
563582 name : 'subgraphName' ,
564583 message : 'Subgraph slug' ,
565584 initial : initSubgraphName ,
566- validate : value => value . length > 0 || 'Subgraph slug must not be empty' ,
585+ validate : value => formatSubgraphName ( value ) . length > 0 || 'Subgraph slug must not be empty' ,
567586 result : value => {
587+ value = formatSubgraphName ( value ) ;
568588 initDebugger . extend ( 'processInitForm' ) ( 'subgraphName: %O' , value ) ;
569589 subgraphName = value ;
570590 return value ;
@@ -575,7 +595,7 @@ async function processInitForm(
575595 type : 'input' ,
576596 name : 'directory' ,
577597 message : 'Directory to create the subgraph in' ,
578- initial : ( ) => initDirectory || getSubgraphBasename ( subgraphName ) ,
598+ initial : ( ) => initDirectory || getSubgraphBasename ( subgraphName ! ) ,
579599 validate : value => value . length > 0 || 'Directory must not be empty' ,
580600 result : value => {
581601 directory = value ;
0 commit comments