Example #1
0
 /**
  * Execute the current command
  */
 private function execute()
 {
     _writeln('PHPLucidFrame %s by Sithu K.', _version());
     _writeln();
     if ($this->command instanceof \LucidFrame\Console\Command) {
         $this->command->run($this->argv);
     } else {
         if (!$this->command && $this->commandName && !in_array($this->commandName, array('-V', '--version'))) {
             _writeln('Command "%s" not found.', $this->commandName);
         } else {
             if (empty($this->command) || in_array($this->command, array('-V', '--version'))) {
                 _writeln(_version());
                 _writeln('PHP Version: %s', phpversion());
                 _writeln('The MIT License');
                 _writeln('Simple, lightweight & yet powerful PHP Application Framework');
                 _writeln('Copyright (c) 2014-%d, phplucidframe.com', date('Y'));
             } else {
                 _writeln('Command "%s" not found.', $this->commandName);
             }
         }
     }
 }
 * @package     PHPLucidFrame\Console
 * @since       PHPLucidFrame v 1.14.0
 * @copyright   Copyright (c), PHPLucidFrame.
 * @author      Sithu K. <*****@*****.**>
 * @link        http://phplucidframe.com
 * @license     http://www.opensource.org/licenses/mit-license.php MIT License
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE
 */
use LucidFrame\Core\SchemaManager;
_consoleCommand('schema:load')->setDescription('Process the schema and import the database')->addArgument('db', 'The database namespace defined in $lc_databases of config.php', 'default')->setDefinition(function (\LucidFrame\Console\Command $cmd) {
    $db = $cmd->getArgument('db');
    $schema = _schema($db);
    if ($schema === null) {
        _writeln('Failed to load schema.');
    } elseif ($schema === false) {
        _writeln('Unable to find the schema file "%s".', DB . 'schema.' . $db . '.php');
    } else {
        if ($cmd->confirm('The database will be purged. Type "y" or "yes" to continue:')) {
            $sm = new SchemaManager($schema);
            if ($sm->import($db)) {
                _writeln('Schema is successfully loaded. The database for "%s" has been imported.', $db);
            } else {
                _writeln('No schema is loaded.');
            }
        } else {
            _writeln('Aborted.');
        }
    }
})->register();
 *
 * Arguments:
 *      db      The database namespace defined in $lc_databases of config.php [default: "default"]
 *
 * @package     PHPLucidFrame\Console
 * @since       PHPLucidFrame v 1.14.0
 * @copyright   Copyright (c), PHPLucidFrame.
 * @author      Sithu K. <*****@*****.**>
 * @link        http://phplucidframe.com
 * @license     http://www.opensource.org/licenses/mit-license.php MIT License
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE
 */
use LucidFrame\Core\SchemaManager;
_consoleCommand('schema:export')->setDescription('Process the schema and export the database sql dump file')->addArgument('db', 'The database namespace defined in $lc_databases of config.php', 'default')->setDefinition(function (\LucidFrame\Console\Command $cmd) {
    $db = $cmd->getArgument('db');
    $schema = _schema($db);
    if ($schema === null) {
        _writeln('Failed to load schema.');
    } elseif ($schema === false) {
        _writeln('Unable to find the schema file "%s".', DB . 'schema.' . $db . '.php');
    } else {
        $sm = new SchemaManager($schema);
        if ($sm->export($db)) {
            _writeln('"%s" has been exported.', DB . 'generated' . _DS_ . 'schema.' . $db . '.sql');
        } else {
            _writeln('No sql file is exported.');
        }
    }
})->register();
 *
 * Arguments:
 *      db      The database namespace defined in $lc_databases of config.php [default: "default"]
 *
 * @package     PHPLucidFrame\Console
 * @since       PHPLucidFrame v 1.16.0
 * @copyright   Copyright (c), PHPLucidFrame.
 * @author      Sithu K. <*****@*****.**>
 * @link        http://phplucidframe.com
 * @license     http://www.opensource.org/licenses/mit-license.php MIT License
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE
 */
use LucidFrame\Core\SchemaManager;
_consoleCommand('schema:build')->setDescription('Build the schema in /db/build/')->addArgument('db', 'The database namespace defined in $lc_databases of config.php', 'default')->setDefinition(function (\LucidFrame\Console\Command $cmd) {
    $db = $cmd->getArgument('db');
    $schema = _schema($db);
    if ($schema === null) {
        _writeln('Failed to load schema.');
    } elseif ($schema === false) {
        _writeln('Unable to find the schema file "%s".', DB . 'schema.' . $db . '.php');
    } else {
        $sm = new SchemaManager($schema);
        if ($sm->build($db)) {
            _writeln('The schema has been build at "db/build/schema.%s.inc".', $db);
        } else {
            _writeln('No schema is loaded.');
        }
    }
})->register();
<?php

/**
 * This file is part of the PHPLucidFrame library.
 * The script executes the command `php lucidframe list [options]`
 *
 * @package     PHPLucidFrame\Console
 * @since       PHPLucidFrame v 1.12.0
 * @copyright   Copyright (c), PHPLucidFrame.
 * @author      Sithu K. <*****@*****.**>
 * @link        http://phplucidframe.com
 * @license     http://www.opensource.org/licenses/mit-license.php MIT License
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE
 */
_consoleCommand('list')->setDescription('List all available commands')->setDefinition(function (\LucidFrame\Console\Command $cmd) {
    $cmd->showHelp();
    _writeln();
    _writeln('Available commands:');
    $table = _consoleTable();
    $commands = _consoleCommands();
    foreach ($commands as $name => $command) {
        $table->addRow()->addColumn($name)->addColumn($command->getDescription());
    }
    $table->hideBorder();
    $table->setPadding(2);
    $table->display();
})->register();
Example #6
0
 /**
  * Display the help message
  * @return void
  */
 public function showHelp()
 {
     $options = $this->getOptions();
     if (count($options)) {
         _writeln('Usage:');
         $usage = _indent() . $this->name . ' [options]';
         if (count($this->arguments)) {
             $usage .= ' [<' . implode('>] [<', $this->argumentNames) . '>]';
         }
         _writeln($usage);
         # Arguments
         if (count($this->arguments)) {
             _writeln();
             _writeln('Arguments:');
             $table = new ConsoleTable();
             $table->hideBorder()->setPadding(2);
             foreach ($this->arguments as $arg) {
                 $table->addRow();
                 $table->addColumn($arg['name']);
                 $desc = $arg['description'];
                 if ($arg['default']) {
                     $desc .= ' [default: "' . $arg['default'] . '"]';
                 }
                 $table->addColumn($desc);
             }
             $table->display();
         }
         # Options
         if (count($options)) {
             _writeln();
             _writeln('Options:');
             $table = new ConsoleTable();
             $table->hideBorder()->setPadding(2);
             foreach ($this->options as $name => $opt) {
                 $table->addRow();
                 $table->addColumn($opt['key']);
                 $desc = $opt['description'];
                 if ($opt['default']) {
                     $desc .= ' [default: "' . $opt['default'] . '"]';
                 }
                 $table->addColumn($desc);
             }
             $table->display();
         }
         if ($this->description) {
             _writeln();
             _writeln('Help:');
             _writeln(_indent() . $this->description);
         }
     }
 }