<?php
+/*
+ Command is a class with following informal interface.
+
+ public $command = 'command name';
+ public $description = 'command description';
+ public function run($args=null) { ... body
+*/
+
class IPF_Cli
{
protected $commands;
public function __construct()
{
$this->commands = array(
- new IPF_Command_Shell,
- new IPF_Command_DebugServer,
- new IPF_Command_Routes,
- new IPF_Command_BuildModels,
- new IPF_Command_BuildContribModels,
- new IPF_Command_Sql,
- new IPF_Command_SyncDB,
- new IPF_Command_Fixtures,
- new IPF_Command_DB,
- new IPF_Command_DBDump,
- new IPF_Command_DBRestore,
- new IPF_Command_CollectStatic,
- new IPF_Command_Pack,
- new IPF_Command_Unpack,
- new IPF_Command_CreateSuperUser,
- new IPF_Command_CreateMigration,
- new IPF_Command_Migrate,
- new IPF_Command_SyncPerms,
+ 'IPF' => array(
+ new IPF_Command_Shell,
+ new IPF_Command_DebugServer,
+ new IPF_Command_Routes,
+ new IPF_Command_BuildModels,
+ new IPF_Command_BuildContribModels,
+ new IPF_Command_Sql,
+ new IPF_Command_SyncDB,
+ new IPF_Command_Fixtures,
+ new IPF_Command_DB,
+ new IPF_Command_DBDump,
+ new IPF_Command_DBRestore,
+ new IPF_Command_CollectStatic,
+ new IPF_Command_Pack,
+ new IPF_Command_Unpack,
+ new IPF_Command_CreateMigration,
+ new IPF_Command_Migrate,
+ new IPF_Command_SyncPerms,
+ ),
);
-
+
+ foreach (IPF_Project::getInstance()->appList() as $app) {
+ $commands = $app->commands();
+ if (count($commands))
+ $this->commands[$app->getName()] = $commands;
+ }
+
+ $project = array();
foreach (IPF::get('commands', array()) as $cmd) {
if (is_string($cmd))
$cmd = new $cmd;
- $this->commands[] = $cmd;
+ $project[] = $cmd;
}
+ if (count($project))
+ $this->commands['Project'] = $project;
}
protected function usage()
{
- print "Usage: php index.php <subcommand> [options] [args]\n\n";
- print "Available subcommands:\n";
+ print "Usage: php index.php <subcommand> [options] [args]\n";
- $rows = array();
- foreach ($this->commands as $command)
- $rows[] = array(
- ' ' . $command->command,
- $command->description,
- );
+ foreach ($this->commands as $group => $commands) {
+ print "\n\033[1;36m$group:\033[0m\n";
- IPF_Shell::displayTwoColumns($rows);
+ foreach ($commands as $command) {
+ echo ' '.str_pad($command->command, 20) . "\t" . $command->description . "\n";
+ }
+ }
print "\n";
}
return;
}
- foreach ($this->commands as $command) {
- if ($command->command === $args[1]) {
- $command->run(array_slice($args, 2));
- return;
+ foreach ($this->commands as $group => $commands) {
+ foreach ($commands as $command) {
+ if ($command->command === $args[1]) {
+ $command->run(array_slice($args, 2));
+ return;
+ }
}
}
+++ /dev/null
-<?php
-
-class IPF_Command_CreateSuperUser
-{
- public $command = 'createsuperuser';
- public $description = 'Create superuser';
-
- public function run($args=null)
- {
- print "Create superuser\n";
-
- $username = $this->readString(" Username: ");
- $password = $this->readString(" Password: ");
- $email = $this->readString(" E-mail: ");
-
- $project = IPF_Project::getInstance();
-
- $su = new User;
- $su->username = $username;
- $su->email = $email;
- $su->is_staff = true;
- $su->is_active = true;
- $su->is_superuser = true;
- $su->setPassword($password);
- $su->save();
- print "Done\n";
- }
-
- private function readString($prompt)
- {
- $value = '';
- while (!$value) {
- print $prompt;
- $value = trim(fgets(STDIN));
- }
- return $value;
- }
-}
-