@@ -22,65 +22,112 @@ export default class AppCreate extends Command {
22
22
description : "ID of the project" ,
23
23
required : false ,
24
24
} ) ,
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
+ } ) ,
25
44
} ;
26
45
27
46
public async run ( ) : Promise < void > {
28
47
const auth = await readAuthConfig ( this ) ;
29
-
30
48
const { flags } = await this . parse ( AppCreate ) ;
49
+ let { projectId, name, description, appName } = flags ;
31
50
32
- let { projectId } = flags ;
33
-
34
- if ( ! projectId ) {
51
+ // Modo interactivo si no se proporcionan los flags necesarios
52
+ if ( ! projectId || ! name || ! appName ) {
35
53
console . log ( chalk . blue . bold ( "\n Listing all Projects \n" ) ) ;
36
-
37
54
const projects = await getProjects ( auth , this ) ;
38
55
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
+ }
50
70
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
+ ] ) ;
52
100
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
+ }
66
104
67
- const appName = await inquirer . prompt ( [
105
+ // Confirmar si no se especifica --skipConfirm
106
+ if ( ! flags . skipConfirm ) {
107
+ const confirm = await inquirer . prompt ( [
68
108
{
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 ,
74
113
} ,
75
114
] ) ;
76
115
116
+ if ( ! confirm . proceed ) {
117
+ this . error ( chalk . yellow ( "Application creation cancelled." ) ) ;
118
+ return ;
119
+ }
120
+ }
121
+
122
+ try {
77
123
const response = await axios . post (
78
124
`${ auth . url } /api/trpc/application.create` ,
79
125
{
80
126
json : {
81
- ...appDetails ,
82
- appName : appName . appName ,
83
- projectId : project . projectId ,
127
+ name,
128
+ appDescription : description ,
129
+ appName,
130
+ projectId,
84
131
} ,
85
132
} ,
86
133
{
@@ -95,9 +142,9 @@ export default class AppCreate extends Command {
95
142
this . error ( chalk . red ( "Error creating application" ) ) ;
96
143
}
97
144
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 } ` ) ) ;
101
148
}
102
149
}
103
150
}
0 commit comments