Further improve CLI commands

This commit is contained in:
Matias Griese 2021-01-06 13:45:19 +02:00
parent 193ab52a35
commit 379033aae4
5 changed files with 121 additions and 43 deletions

15
bin/gpm
View File

@ -2,8 +2,8 @@
<?php
use Grav\Common\Composer;
use Symfony\Component\Console\Application;
use Grav\Common\Grav;
use Grav\Console\Application\GpmApplication;
\define('GRAV_CLI', true);
\define('GRAV_REQUEST_TIME', microtime(true));
@ -45,16 +45,5 @@ if (!function_exists('curl_version')) {
$grav = Grav::instance(array('loader' => $autoload));
$app = new Application('Grav Package Manager', GRAV_VERSION);
$app->addCommands(array(
new \Grav\Console\Gpm\IndexCommand(),
new \Grav\Console\Gpm\VersionCommand(),
new \Grav\Console\Gpm\InfoCommand(),
new \Grav\Console\Gpm\InstallCommand(),
new \Grav\Console\Gpm\UninstallCommand(),
new \Grav\Console\Gpm\UpdateCommand(),
new \Grav\Console\Gpm\SelfupgradeCommand(),
new \Grav\Console\Gpm\DirectInstallCommand(),
));
$app = new GpmApplication('Grav Package Manager', GRAV_VERSION);
$app->run();

View File

@ -3,8 +3,7 @@
use Grav\Common\Composer;
use Grav\Common\Grav;
use Grav\Console\Cli;
use Symfony\Component\Console\Application;
use Grav\Console\Application\GravApplication;
\define('GRAV_CLI', true);
\define('GRAV_REQUEST_TIME', microtime(true));
@ -42,20 +41,5 @@ if (!file_exists(GRAV_ROOT . '/index.php')) {
exit('FATAL: Must be run from ROOT directory of Grav!');
}
$app = new Application('Grav CLI Application', GRAV_VERSION);
$app->addCommands(array(
new Cli\InstallCommand(),
new Cli\ComposerCommand(),
new Cli\SandboxCommand(),
new Cli\CleanCommand(),
new Cli\ClearCacheCommand(),
new Cli\BackupCommand(),
new Cli\NewProjectCommand(),
new Cli\SchedulerCommand(),
new Cli\SecurityCommand(),
new Cli\LogViewerCommand(),
new Cli\YamlLinterCommand(),
new Cli\ServerCommand(),
new Cli\PageSystemValidatorCommand(),
));
$app = new GravApplication('Grav CLI Application', GRAV_VERSION);
$app->run();

View File

@ -0,0 +1,43 @@
<?php
/**
* @package Grav\Console
*
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Console\Application;
use Codeception\Application;
use Grav\Console\Gpm\DirectInstallCommand;
use Grav\Console\Gpm\IndexCommand;
use Grav\Console\Gpm\InfoCommand;
use Grav\Console\Gpm\InstallCommand;
use Grav\Console\Gpm\SelfupgradeCommand;
use Grav\Console\Gpm\UninstallCommand;
use Grav\Console\Gpm\UpdateCommand;
use Grav\Console\Gpm\VersionCommand;
/**
* Class GpmApplication
* @package Grav\Console\Application
*/
class GpmApplication extends Application
{
public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
{
parent::__construct($name, $version);
$this->addCommands([
new IndexCommand(),
new VersionCommand(),
new InfoCommand(),
new InstallCommand(),
new UninstallCommand(),
new UpdateCommand(),
new SelfupgradeCommand(),
new DirectInstallCommand(),
]);
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* @package Grav\Console
*
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Console\Application;
use Codeception\Application;
use Grav\Console\Cli\BackupCommand;
use Grav\Console\Cli\CleanCommand;
use Grav\Console\Cli\ClearCacheCommand;
use Grav\Console\Cli\ComposerCommand;
use Grav\Console\Cli\InstallCommand;
use Grav\Console\Cli\LogViewerCommand;
use Grav\Console\Cli\NewProjectCommand;
use Grav\Console\Cli\PageSystemValidatorCommand;
use Grav\Console\Cli\SandboxCommand;
use Grav\Console\Cli\SchedulerCommand;
use Grav\Console\Cli\SecurityCommand;
use Grav\Console\Cli\ServerCommand;
use Grav\Console\Cli\YamlLinterCommand;
/**
* Class GravApplication
* @package Grav\Console\Application
*/
class GravApplication extends Application
{
public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
{
parent::__construct($name, $version);
$this->addCommands([
new InstallCommand(),
new ComposerCommand(),
new SandboxCommand(),
new CleanCommand(),
new ClearCacheCommand(),
new BackupCommand(),
new NewProjectCommand(),
new SchedulerCommand(),
new SecurityCommand(),
new LogViewerCommand(),
new YamlLinterCommand(),
new ServerCommand(),
new PageSystemValidatorCommand(),
]);
}
}

View File

@ -19,6 +19,7 @@ use Grav\Console\Cli\ClearCacheCommand;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\File\YamlFile;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
@ -76,12 +77,16 @@ trait ConsoleTrait
*/
final protected function addEnvOption()
{
return $this->addOption(
'env',
'e',
InputOption::VALUE_OPTIONAL,
'Optional environment to trigger a specific configuration.'
);
try {
return $this->addOption(
'env',
'e',
InputOption::VALUE_OPTIONAL,
'Optional environment to trigger a specific configuration.'
);
} catch (LogicException $e) {
return $this;
}
}
/**
@ -89,12 +94,16 @@ trait ConsoleTrait
*/
final protected function addLanguageOption()
{
return $this->addOption(
'language',
'l',
InputOption::VALUE_OPTIONAL,
'Optional language to be used (multi-language sites only).'
);
try {
return $this->addOption(
'language',
'l',
InputOption::VALUE_OPTIONAL,
'Optional language to be used (multi-language sites only).'
);
} catch (LogicException $e) {
return $this;
}
}
final protected function setupGrav(): void