1515
1616use CodeIgniter \CLI \AbstractCommand ;
1717use CodeIgniter \CLI \Attributes \Command ;
18- use CodeIgniter \CLI \CLI ;
1918use CodeIgniter \CLI \Input \Argument ;
2019use CodeIgniter \CLI \Input \Option ;
2120use CodeIgniter \Config \Factories ;
@@ -53,7 +52,7 @@ protected function configure(): void
5352 protected function interact (array &$ arguments , array &$ options ): void
5453 {
5554 if ($ arguments === []) {
56- $ arguments [] = CLI :: prompt ('Database name ' , null , 'required ' );
55+ $ arguments [] = $ this -> getPrompt ()-> ask ('Database name ' , null , 'required ' );
5756 }
5857
5958 $ ext = $ this ->getUnboundOption ('ext ' , $ options );
@@ -71,6 +70,8 @@ protected function execute(array $arguments, array $options): int
7170 $ name = $ arguments ['db_name ' ];
7271 assert (is_string ($ name ));
7372
73+ $ output = $ this ->getOutput ();
74+
7475 try {
7576 $ config = config (Database::class);
7677
@@ -86,7 +87,7 @@ protected function execute(array $arguments, array $options): int
8687 assert (is_string ($ ext ));
8788
8889 if (! in_array ($ ext , self ::VALID_EXTENSIONS , true )) {
89- CLI :: error (sprintf ('Invalid file extension "%s". Use either `db` or `sqlite`. ' , $ ext ), 'light_gray ' , 'red ' );
90+ $ output -> error (sprintf ('Invalid file extension "%s". Use either `db` or `sqlite`. ' , $ ext ), 'light_gray ' , 'red ' );
9091
9192 return EXIT_ERROR ;
9293 }
@@ -102,7 +103,7 @@ protected function execute(array $arguments, array $options): int
102103 $ dbName = str_contains ($ name , DIRECTORY_SEPARATOR ) ? $ name : WRITEPATH . $ name ;
103104
104105 if (is_file ($ dbName )) {
105- CLI :: error ("Database \"{$ dbName }\" already exists. " , 'light_gray ' , 'red ' );
106+ $ output -> error ("Database \"{$ dbName }\" already exists. " , 'light_gray ' , 'red ' );
106107
107108 return EXIT_ERROR ;
108109 }
@@ -116,18 +117,18 @@ protected function execute(array $arguments, array $options): int
116117
117118 if (! is_file ($ db ->getDatabase ()) && $ name !== ':memory: ' ) {
118119 // @codeCoverageIgnoreStart
119- CLI :: error ('Database creation failed. ' , 'light_gray ' , 'red ' );
120+ $ output -> error ('Database creation failed. ' , 'light_gray ' , 'red ' );
120121
121122 return EXIT_ERROR ;
122123 // @codeCoverageIgnoreEnd
123124 }
124125 } elseif (! Database ::forge ()->createDatabase ($ name )) {
125- CLI :: error ('Database creation failed. ' , 'light_gray ' , 'red ' );
126+ $ output -> error ('Database creation failed. ' , 'light_gray ' , 'red ' );
126127
127128 return EXIT_ERROR ;
128129 }
129130
130- CLI :: write ("Database \"{$ name }\" successfully created. " , 'green ' );
131+ $ output -> write ("Database \"{$ name }\" successfully created. " , 'green ' );
131132
132133 return EXIT_SUCCESS ;
133134 } catch (Throwable $ e ) {
0 commit comments