Skip to content

Commit 58b2e6a

Browse files
committed
add create Model cmd
1 parent 54a169c commit 58b2e6a

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/Ubiquity/devtools/cmd/Command.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,35 @@ public static function controller() {
170170
], 'controllers');
171171
}
172172

173+
public static function genModel() {
174+
return new Command("model", "tableName", "Generates a new model from an existing table.", [
175+
'gen_model',
176+
'gen:model',
177+
'gen-model',
178+
'genModel'
179+
], [
180+
'd' => Parameter::create('database', 'The database connection to use', [], 'default'),
181+
'a' => Parameter::create('access', 'The default access to the class members', [], 'private'),
182+
'o' => Parameter::create('domain', 'The domain in which to create the model.', [], '')
183+
], [
184+
'Ubiquity genModel User',
185+
'Ubiquity genModel Author -d=projects',
186+
'Ubiquity genModel Author -d=projects -a=protected'
187+
], 'models');
188+
}
189+
173190
public static function model() {
174-
return new Command("model", "tableName", "Generates a new model.", [
191+
return new Command("model", "modelName", "Generates a new model from scratch.", [
175192
'create_model',
176193
'create:model',
177194
'create-model',
178195
'createModel'
179196
], [
180197
'd' => Parameter::create('database', 'The database connection to use', [], 'default'),
181-
'a' => Parameter::create('access', 'The default access to the class members', [], 'private'),
182198
'o' => Parameter::create('domain', 'The domain in which to create the model.', [], '')
183199
], [
184200
'Ubiquity model User',
185-
'Ubiquity model Author -d=projects',
186-
'Ubiquity model Author -d=projects -a=protected'
201+
'Ubiquity model Author -d=projects'
187202
], 'models');
188203
}
189204

@@ -852,6 +867,7 @@ public static function getCommands() {
852867
self::help(),
853868
self::version(),
854869
self::model(),
870+
self::genModel(),
855871
self::allModels(),
856872
self::infoMigrations(),
857873
self::migrations(),

src/Ubiquity/devtools/cmd/Console.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public static function readline() {
2727
* @param ?array $propositions
2828
* @return string
2929
*/
30-
public static function question($prompt, array $propositions = null) {
30+
public static function question($prompt, array $propositions = null,array $options=[]) {
31+
if(isset($options['default'])){
32+
$prompt.=" (default:".$options['default'].")";
33+
}
3134
echo ConsoleFormatter::colorize($prompt, ConsoleFormatter::BLACK, ConsoleFormatter::BG_YELLOW);
3235
if (\is_array($propositions)) {
3336
if (\count($propositions) > 2) {
@@ -49,7 +52,9 @@ public static function question($prompt, array $propositions = null) {
4952
} else {
5053
$answer = self::readline();
5154
}
52-
55+
if(isset($options['default']) && $answer==''){
56+
$answer=$options['default'];
57+
}
5358
return $answer;
5459
}
5560

0 commit comments

Comments
 (0)