@@ -22,65 +22,112 @@ export default class AppCreate extends Command {
2222 description : "ID of the project" ,
2323 required : false ,
2424 } ) ,
25+ name : Flags . string ( {
26+ char : "n" ,
27+ description : "Application name" ,
28+ required : false ,
29+ } ) ,
30+ description : Flags . string ( {
31+ char : "d" ,
32+ description : "Application description" ,
33+ required : false ,
34+ } ) ,
35+ appName : Flags . string ( {
36+ description : "Docker app name" ,
37+ required : false ,
38+ } ) ,
39+ skipConfirm : Flags . boolean ( {
40+ char : "y" ,
41+ description : "Skip confirmation prompt" ,
42+ default : false ,
43+ } ) ,
2544 } ;
2645
2746 public async run ( ) : Promise < void > {
2847 const auth = await readAuthConfig ( this ) ;
29-
3048 const { flags } = await this . parse ( AppCreate ) ;
49+ let { projectId, name, description, appName } = flags ;
3150
32- let { projectId } = flags ;
33-
34- if ( ! projectId ) {
51+ // Modo interactivo si no se proporcionan los flags necesarios
52+ if ( ! projectId || ! name || ! appName ) {
3553 console . log ( chalk . blue . bold ( "\n Listing all Projects \n" ) ) ;
36-
3754 const projects = await getProjects ( auth , this ) ;
3855
39- const { project } = await inquirer . prompt < Answers > ( [
40- {
41- choices : projects . map ( ( project ) => ( {
42- name : project . name ,
43- value : project ,
44- } ) ) ,
45- message : "Select a project to create the application in:" ,
46- name : "project" ,
47- type : "list" ,
48- } ,
49- ] ) ;
56+ if ( ! projectId ) {
57+ const { project } = await inquirer . prompt < Answers > ( [
58+ {
59+ choices : projects . map ( ( project ) => ( {
60+ name : project . name ,
61+ value : project ,
62+ } ) ) ,
63+ message : "Select a project to create the application in:" ,
64+ name : "project" ,
65+ type : "list" ,
66+ } ,
67+ ] ) ;
68+ projectId = project . projectId ;
69+ }
5070
51- projectId = project . projectId ;
71+ if ( ! name || ! appName ) {
72+ const appDetails = await inquirer . prompt ( [
73+ {
74+ message : "Enter the application name:" ,
75+ name : "name" ,
76+ type : "input" ,
77+ validate : ( input ) => ( input ? true : "Application name is required" ) ,
78+ default : name ,
79+ } ,
80+ {
81+ message : "Enter the application description (optional):" ,
82+ name : "appDescription" ,
83+ type : "input" ,
84+ default : description ,
85+ } ,
86+ ] ) ;
87+
88+ name = appDetails . name ;
89+ description = appDetails . appDescription ;
90+
91+ const appNamePrompt = await inquirer . prompt ( [
92+ {
93+ default : appName || `${ slugify ( name ) } ` ,
94+ message : "Enter the App name:" ,
95+ name : "appName" ,
96+ type : "input" ,
97+ validate : ( input ) => ( input ? true : "App name is required" ) ,
98+ } ,
99+ ] ) ;
52100
53- const appDetails = await inquirer . prompt ( [
54- {
55- message : "Enter the application name:" ,
56- name : "name" ,
57- type : "input" ,
58- validate : ( input ) => ( input ? true : "Application name is required" ) ,
59- } ,
60- {
61- message : "Enter the application description (optional):" ,
62- name : "appDescription" ,
63- type : "input" ,
64- } ,
65- ] ) ;
101+ appName = appNamePrompt . appName ;
102+ }
103+ }
66104
67- const appName = await inquirer . prompt ( [
105+ // Confirmar si no se especifica --skipConfirm
106+ if ( ! flags . skipConfirm ) {
107+ const confirm = await inquirer . prompt ( [
68108 {
69- default : `${ slugify ( project . name ) } -${ appDetails . name } ` ,
70- message : "Enter the App name: (optional):" ,
71- name : "appName" ,
72- type : "input" ,
73- validate : ( input ) => ( input ? true : "App name is required" ) ,
109+ type : 'confirm' ,
110+ name : 'proceed' ,
111+ message : 'Do you want to create this application?' ,
112+ default : false ,
74113 } ,
75114 ] ) ;
76115
116+ if ( ! confirm . proceed ) {
117+ this . error ( chalk . yellow ( "Application creation cancelled." ) ) ;
118+ return ;
119+ }
120+ }
121+
122+ try {
77123 const response = await axios . post (
78124 `${ auth . url } /api/trpc/application.create` ,
79125 {
80126 json : {
81- ...appDetails ,
82- appName : appName . appName ,
83- projectId : project . projectId ,
127+ name,
128+ appDescription : description ,
129+ appName,
130+ projectId,
84131 } ,
85132 } ,
86133 {
@@ -95,9 +142,9 @@ export default class AppCreate extends Command {
95142 this . error ( chalk . red ( "Error creating application" ) ) ;
96143 }
97144
98- this . log (
99- chalk . green ( `Application ' ${ appDetails . name } ' created successfully.` ) ,
100- ) ;
145+ this . log ( chalk . green ( `Application ' ${ name } ' created successfully.` ) ) ;
146+ } catch ( error : any ) {
147+ this . error ( chalk . red ( `Error creating application: ${ error . message } ` ) ) ;
101148 }
102149 }
103150}
0 commit comments