Skip to content

Commit 6bb36a2

Browse files
committed
Add category to command
1 parent f996bf4 commit 6bb36a2

File tree

1 file changed

+82
-44
lines changed

1 file changed

+82
-44
lines changed

src/Ubiquity/devtools/cmd/Command.php

Lines changed: 82 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ class Command {
2727

2828
protected $examples;
2929

30+
protected $category;
31+
3032
protected static $customCommands;
3133

3234
protected static $customAliases;
3335

34-
public function __construct($name, $value, $description, $aliases = [], $parameters = [], $examples = []) {
36+
public function __construct($name = '', $value = '', $description = '', $aliases = [], $parameters = [], $examples = [], $category = 'custom') {
3537
$this->name = $name;
3638
$this->value = $value;
3739
$this->description = $description;
3840
$this->aliases = $aliases;
3941
$this->parameters = $parameters;
4042
$this->examples = $examples;
43+
$this->category = $category;
4144
}
4245

4346
public function simpleString() {
@@ -145,7 +148,7 @@ public static function project() {
145148
'Creates a new project' => 'Ubiquity new blog',
146149
'With admin interface' => 'Ubiquity new blog -a',
147150
'and models generation' => 'Ubiquity new blog -a -m -b=blogDB'
148-
]);
151+
], 'installation');
149152
}
150153

151154
public static function controller() {
@@ -159,7 +162,7 @@ public static function controller() {
159162
], [
160163
'Creates a controller' => 'Ubiquity controller UserController',
161164
'with its associated view' => 'Ubiquity controller UserController -v'
162-
]);
165+
], 'controllers');
163166
}
164167

165168
public static function model() {
@@ -170,7 +173,7 @@ public static function model() {
170173
], [
171174
'Ubiquity model User',
172175
'Ubiquity model Author -d=projects'
173-
]);
176+
], 'models');
174177
}
175178

176179
public static function routes() {
@@ -197,11 +200,11 @@ public static function routes() {
197200
'Ubiquity info:routes',
198201
'Ubiquity info:routes -type=rest',
199202
'Only the routes with the method post' => 'Ubiquity info:routes -type=rest -m=-post'
200-
]);
203+
], 'router');
201204
}
202205

203206
public static function version() {
204-
return new Command("version", "", "Return PHP, Framework and dev-tools versions.");
207+
return new Command("version", "", "Return PHP, Framework and dev-tools versions.", [], [], [], 'system');
205208
}
206209

207210
public static function allModels() {
@@ -212,7 +215,7 @@ public static function allModels() {
212215
], [
213216
'Ubiquity all-models',
214217
'Ubiquity all-models -d=projects'
215-
]);
218+
], 'models');
216219
}
217220

218221
public static function clearCache() {
@@ -225,11 +228,11 @@ public static function clearCache() {
225228
"models",
226229
"queries",
227230
"views"
228-
])
231+
], 'all')
229232
], [
230233
'Clear all caches' => 'Ubiquity clear-cache -t=all',
231234
'Clear models cache' => 'Ubiquity clear-cache -t=models'
232-
]);
235+
], 'cache');
233236
}
234237

235238
public static function initCache() {
@@ -239,11 +242,11 @@ public static function initCache() {
239242
"controllers",
240243
"rest",
241244
"models"
242-
])
245+
], 'all')
243246
], [
244247
'Init all caches' => 'Ubiquity init-cache',
245248
'Init models cache' => 'Ubiquity init-cache -t=models'
246-
]);
249+
], 'cache');
247250
}
248251

249252
public static function serve() {
@@ -258,21 +261,21 @@ public static function serve() {
258261
], [
259262
'Starts a php server at 127.0.0.1:8090' => 'Ubiquity serve',
260263
'Starts a reactPHP server at 127.0.0.1:8080' => 'Ubiquity serve -t=react'
261-
]);
264+
], 'servers');
262265
}
263266

264267
public static function selfUpdate() {
265-
return new Command("self-update", "", "Updates Ubiquity framework for the current project.", [], []);
268+
return new Command("self-update", "", "Updates Ubiquity framework for the current project.", [], [], [], 'installation');
266269
}
267270

268271
public static function admin() {
269-
return new Command("admin", "", "Add UbiquityMyAdmin webtools to the current project.", [], []);
272+
return new Command("admin", "", "Add UbiquityMyAdmin webtools to the current project.", [], [], [], 'installation');
270273
}
271274

272275
public static function help() {
273276
return new Command("help", "?", "Get some help about a dev-tools command.", [], [], [
274277
'Get some help about crud' => 'Ubiquity help crud'
275-
]);
278+
], 'system');
276279
}
277280

278281
public static function crudController() {
@@ -303,7 +306,7 @@ public static function crudController() {
303306
'and associates a route to it' => 'Ubiquity crud CrudUsers -r=User -p=/users',
304307
'allows customization of index and form templates' => 'Ubiquity crud CrudUsers -r=User -t=index,form',
305308
'Creates a crud controller for the class models\projects\Author' => 'Ubiquity crud Authors -r=models\projects\Author'
306-
]);
309+
], 'controllers');
307310
}
308311

309312
public static function restController() {
@@ -314,7 +317,7 @@ public static function restController() {
314317
"p" => Parameter::create("path", "The associated route", [])
315318
], [
316319
'Creates a REST controller for the class models\User' => 'Ubiquity rest RestUsers -r=User -p=/rest/users'
317-
]);
320+
], 'rest');
318321
}
319322

320323
public static function restApiController() {
@@ -324,7 +327,7 @@ public static function restApiController() {
324327
"p" => Parameter::create("path", "The associated route", [])
325328
], [
326329
'Creates a REST API controller' => 'Ubiquity restapi -p=/rest'
327-
]);
330+
], 'rest');
328331
}
329332

330333
public static function dao() {
@@ -341,7 +344,7 @@ public static function dao() {
341344
'Returns all instances of models\User and includes their commands' => 'Ubiquity dao getAll -r=User -i=commands',
342345
'Returns the User with the id 5' => 'Ubiquity dao getOne -c="id=5"-r=User',
343346
'Returns the list of users belonging to the "Brittany" or "Normandy" regions' => 'Ubiquity uGetAll -r=User -c="region.name= ? or region.name= ?" -p=Brittany,Normandy'
344-
]);
347+
], 'models');
345348
}
346349

347350
public static function authController() {
@@ -362,7 +365,7 @@ public static function authController() {
362365
'Creates a new controller for authentification' => 'Ubiquity auth AdminAuthController',
363366
'and associates a route to it' => 'Ubiquity auth AdminAuthController -p=/admin/auth',
364367
'allows customization of index and info templates' => 'Ubiquity auth AdminAuthController -t=index,info'
365-
]);
368+
], 'controllers');
366369
}
367370

368371
public static function newAction() {
@@ -378,7 +381,7 @@ public static function newAction() {
378381
'and associates a route to it' => 'Ubiquity action Users.display -p=idUser -r=/users/display/{idUser}',
379382
'with multiple parameters' => 'Ubiquity action Users.search -p=name,address',
380383
'and create the associated view' => 'Ubiquity action Users.search -p=name,address -v'
381-
]);
384+
], 'controllers');
382385
}
383386

384387
public static function infoModel() {
@@ -390,7 +393,7 @@ public static function infoModel() {
390393
"f" => Parameter::create("fields", "The fields to display in the table.", [])
391394
], [
392395
'Gets metadatas for User class' => 'Ubiquity info:model -m=User'
393-
]);
396+
], 'models');
394397
}
395398

396399
public static function infoModels() {
@@ -403,7 +406,7 @@ public static function infoModels() {
403406
'Gets metadatas for all models' => 'Ubiquity info:models',
404407
'Gets metadatas for User and Group models' => 'Ubiquity info:models -m=User,Group',
405408
'Gets all primary keys for all models' => 'Ubiquity info:models -f=#primaryKeys'
406-
]);
409+
], 'models');
407410
}
408411

409412
public static function infoValidation() {
@@ -417,7 +420,7 @@ public static function infoValidation() {
417420
], [
418421
'Gets validators for User class' => 'Ubiquity info:validation -m=User',
419422
'Gets validators for User class on member firstname' => 'Ubiquity info:validation firstname -m=User'
420-
]);
423+
], 'models');
421424
}
422425

423426
public static function configInfo() {
@@ -429,7 +432,7 @@ public static function configInfo() {
429432
], [
430433
'Display all config vars' => 'Ubiquity config',
431434
'Display database config vars' => 'Ubiquity config -f=database'
432-
]);
435+
], 'system');
433436
}
434437

435438
public static function configSet() {
@@ -440,7 +443,7 @@ public static function configSet() {
440443
], [], [
441444
'Assigns a new value to siteURL' => 'Ubiquity config:set --siteURL=http://127.0.0.1/quick-start/',
442445
'Change the database name and port' => 'Ubiquity config:set --database.dbName=blog --database.port=3307'
443-
]);
446+
], 'system');
444447
}
445448

446449
public static function newTheme() {
@@ -455,7 +458,7 @@ public static function newTheme() {
455458
], [
456459
'Creates a new theme custom' => 'Ubiquity create-theme custom',
457460
'Creates a new theme inheriting from Bootstrap' => 'Ubiquity theme myBootstrap -x=bootstrap'
458-
]);
461+
], 'gui');
459462
}
460463

461464
public static function installTheme() {
@@ -465,7 +468,7 @@ public static function installTheme() {
465468
], [], [
466469
'Creates a new theme custom' => 'Ubiquity theme custom',
467470
'Install bootstrap theme' => 'Ubiquity theme bootstrap'
468-
]);
471+
], 'gui');
469472
}
470473

471474
public static function bootstrap() {
@@ -474,7 +477,7 @@ public static function bootstrap() {
474477
], [], [
475478
'Bootstrap for dev mode' => 'Ubiquity bootstrap dev',
476479
'Bootstrap for prod mode' => 'Ubiquity bootstrap prod'
477-
]);
480+
], 'servers');
478481
}
479482

480483
public static function composer() {
@@ -484,15 +487,15 @@ public static function composer() {
484487
'composer update' => 'Ubiquity composer update',
485488
'composer update with no-dev' => 'Ubiquity composer nodev',
486489
'composer optimization for production' => 'Ubiquity composer optimize'
487-
]);
490+
], 'system');
488491
}
489492

490493
public static function mailer() {
491494
return new Command("mailer", "part", "Displays mailer classes, mailer queue or mailer dequeue.", [], [], [
492495
'Display mailer classes' => 'Ubiquity mailer classes',
493496
'Display mailer messages in queue(To send)' => 'Ubiquity mailer queue',
494497
'Display mailer messages in dequeue(sent)' => 'Ubiquity mailer dequeue'
495-
]);
498+
], 'mailer');
496499
}
497500

498501
public static function sendMails() {
@@ -503,7 +506,7 @@ public static function sendMails() {
503506
], [
504507
'Send all messages to send from queue' => 'Ubiquity semdmails',
505508
'Send the first message in queue' => 'Ubiquity sendmail 1'
506-
]);
509+
], 'mailer');
507510
}
508511

509512
public static function newMail() {
@@ -512,7 +515,7 @@ public static function newMail() {
512515
"new:mail"
513516
], [], [
514517
'Creates a new mailer class' => 'Ubiquity newMail InformationMail'
515-
]);
518+
], 'mailer');
516519
}
517520

518521
public static function createCommand() {
@@ -526,14 +529,16 @@ public static function createCommand() {
526529
"a" => Parameter::create("aliases", "The command aliases (comma separated).", [])
527530
], [
528531
'Creates a new custom command' => 'Ubiquity create-command custom'
529-
]);
532+
], 'system');
530533
}
531534

532535
protected static function getCustomCommandInfos() {
533536
$result = [];
534537
$commands = self::getCustomCommands();
535-
foreach ($commands as $o) {
536-
$result[] = $o->getCommand();
538+
if (is_array($commands)) {
539+
foreach ($commands as $o) {
540+
$result[] = $o->getCommand();
541+
}
537542
}
538543
return $result;
539544
}
@@ -577,33 +582,34 @@ public static function preloadCustomCommands(array $config = []) {
577582

578583
public static function getCommands() {
579584
return [
585+
self::initCache(),
586+
self::clearCache(),
587+
self::controller(),
588+
self::newAction(),
589+
self::authController(),
590+
self::crudController(),
591+
self::newTheme(),
592+
self::installTheme(),
593+
580594
self::project(),
581595
self::serve(),
582596
self::bootstrap(),
583597
self::help(),
584598
self::version(),
585-
self::controller(),
586599
self::model(),
587600
self::allModels(),
588601
self::dao(),
589-
self::clearCache(),
590-
self::initCache(),
591602
self::selfUpdate(),
592603
self::composer(),
593604
self::admin(),
594-
self::crudController(),
595-
self::authController(),
596605
self::restController(),
597606
self::restApiController(),
598-
self::newAction(),
599607
self::routes(),
600608
self::infoModel(),
601609
self::infoModels(),
602610
self::infoValidation(),
603611
self::configInfo(),
604612
self::configSet(),
605-
self::installTheme(),
606-
self::newTheme(),
607613
self::mailer(),
608614
self::newMail(),
609615
self::sendMails(),
@@ -651,4 +657,36 @@ public function getAliases() {
651657
public function getParameters() {
652658
return $this->parameters;
653659
}
660+
661+
/**
662+
*
663+
* @return mixed
664+
*/
665+
public function getCategory() {
666+
return $this->category;
667+
}
668+
669+
/**
670+
*
671+
* @param mixed $category
672+
*/
673+
public function setCategory($category) {
674+
$this->category = $category;
675+
}
676+
677+
public function hasParameters() {
678+
return count($this->parameters) > 0;
679+
}
680+
681+
public function hasValue() {
682+
return $this->value != null;
683+
}
684+
685+
public function isImmediate() {
686+
return ! $this->hasParameters() && ! $this->hasValue();
687+
}
688+
689+
public function __toString() {
690+
return $this->name;
691+
}
654692
}

0 commit comments

Comments
 (0)