Cleaned up Console commands, now extending Grav's own ConsoleCommand class

This commit is contained in:
Djamil Legato
2015-11-17 19:31:13 -08:00
parent 698015a03d
commit 3e081b340f
16 changed files with 144 additions and 258 deletions

View File

@@ -2,23 +2,17 @@
namespace Grav\Console\Cli;
use Grav\Common\Backup\ZipBackup;
use Grav\Console\ConsoleTrait;
use Grav\Console\ConsoleCommand;
use RocketTheme\Toolbox\File\JsonFile;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class BackupCommand
* @package Grav\Console\Cli
*/
class BackupCommand extends Command
class BackupCommand extends ConsoleCommand
{
use ConsoleTrait;
protected $source;
protected $progress;
@@ -42,21 +36,16 @@ class BackupCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->progress = new ProgressBar($output);
$this->progress = new ProgressBar($this->output);
$this->progress->setFormat('Archiving <cyan>%current%</cyan> files [<green>%bar%</green>] %elapsed:6s% %memory:6s%');
self::getGrav()['config']->init();
$destination = ($input->getArgument('destination')) ? $input->getArgument('destination') : null;
$destination = ($this->input->getArgument('destination')) ? $this->input->getArgument('destination') : null;
$log = JsonFile::instance(self::getGrav()['locator']->findResource("log://backup.log", true, true));
$backup = ZipBackup::backup($destination, [$this, 'output']);
@@ -66,16 +55,13 @@ class BackupCommand extends Command
]);
$log->save();
$output->writeln('');
$output->writeln('');
$this->output->writeln('');
$this->output->writeln('');
}
/**
* @param $folder
* @param $zipFile
* @param $exclusiveLength
* @param $progress
* @param $args
*/
public function output($args)
{

View File

@@ -2,20 +2,14 @@
namespace Grav\Console\Cli;
use Grav\Common\Filesystem\Folder;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Grav\Console\ConsoleCommand;
/**
* Class CleanCommand
* @package Grav\Console\Cli
*/
class CleanCommand extends Command
class CleanCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var array
*/
@@ -172,14 +166,10 @@ class CleanCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->cleanPaths();
}

View File

@@ -2,29 +2,24 @@
namespace Grav\Console\Cli;
use Grav\Common\Cache;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputInterface;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class ClearCacheCommand
* @package Grav\Console\Cli
*/
class ClearCacheCommand extends Command
class ClearCacheCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
*
*/
protected function configure()
{
$this
->setName("clear-cache")
->setDescription("Clears Grav cache")
->setName('clear-cache')
->setAliases(['clearcache'])
->setDescription('Clears Grav cache')
->addOption('all', null, InputOption::VALUE_NONE, 'If set will remove all including compiled, twig, doctrine caches')
->addOption('assets-only', null, InputOption::VALUE_NONE, 'If set will remove only assets/*')
->addOption('images-only', null, InputOption::VALUE_NONE, 'If set will remove only images/*')
@@ -33,14 +28,10 @@ class ClearCacheCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->cleanPaths();
}

View File

@@ -1,23 +1,16 @@
<?php
namespace Grav\Console\Cli;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
/**
* Class ComposerCommand
* @package Grav\Console\Cli
*/
class ComposerCommand extends Command
class ComposerCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -59,24 +52,19 @@ class ComposerCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$action = $this->input->getOption('install') ? 'install' : ($this->input->getOption('update') ? 'update' : 'install');
$action = $input->getOption('install') ? 'install' : ($input->getOption('update') ? 'update' : 'install');
if ($input->getOption('install')) {
if ($this->input->getOption('install')) {
$action = 'install';
}
// Updates composer first
$output->writeln("\nInstalling vendor dependencies");
$output->writeln($this->composerUpdate(GRAV_ROOT, $action));
$this->output->writeln("\nInstalling vendor dependencies");
$this->output->writeln($this->composerUpdate(GRAV_ROOT, $action));
}
}

View File

@@ -1,22 +1,17 @@
<?php
namespace Grav\Console\Cli;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
/**
* Class InstallCommand
* @package Grav\Console\Cli
*/
class InstallCommand extends Command
class InstallCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -58,17 +53,12 @@ class InstallCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$dependencies_file = '.dependencies';
$this->destination = ($input->getArgument('destination')) ? $input->getArgument('destination') : ROOT_DIR;
$this->destination = ($this->input->getArgument('destination')) ? $this->input->getArgument('destination') : ROOT_DIR;
// fix trailing slash
$this->destination = rtrim($this->destination, DS) . DS;
@@ -78,7 +68,7 @@ class InstallCommand extends Command
$local_config_file = exec('eval echo ~/.grav/config');
if (file_exists($local_config_file)) {
$this->local_config = Yaml::parse($local_config_file);
$output->writeln('Read local config from <cyan>' . $local_config_file . '</cyan>');
$this->output->writeln('Read local config from <cyan>' . $local_config_file . '</cyan>');
}
}
@@ -88,22 +78,22 @@ class InstallCommand extends Command
} elseif (file_exists($this->destination . $dependencies_file)) {
$this->config = Yaml::parse($this->destination . $dependencies_file);
} else {
$output->writeln('<red>ERROR</red> Missing .dependencies file in <cyan>user/</cyan> folder');
$this->output->writeln('<red>ERROR</red> Missing .dependencies file in <cyan>user/</cyan> folder');
}
// If yaml config, process
if ($this->config) {
if (!$input->getOption('symlink')) {
if (!$this->input->getOption('symlink')) {
// Updates composer first
$output->writeln("\nInstalling vendor dependencies");
$output->writeln($this->composerUpdate(GRAV_ROOT, 'install'));
$this->output->writeln("\nInstalling vendor dependencies");
$this->output->writeln($this->composerUpdate(GRAV_ROOT, 'install'));
$this->gitclone();
} else {
$this->symlink();
}
} else {
$output->writeln('<red>ERROR</red> invalid YAML in ' . $dependencies_file);
$this->output->writeln('<red>ERROR</red> invalid YAML in ' . $dependencies_file);
}

View File

@@ -1,29 +1,25 @@
<?php
namespace Grav\Console\Cli;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class NewProjectCommand
* @package Grav\Console\Cli
*/
class NewProjectCommand extends Command
class NewProjectCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
*
*/
protected function configure()
{
$this
->setName("new-project")
->setName('new-project')
->setAliases(['newproject'])
->addArgument(
'destination',
InputArgument::REQUIRED,
@@ -35,37 +31,32 @@ class NewProjectCommand extends Command
InputOption::VALUE_NONE,
'Symlink the required bits'
)
->setDescription("Creates a new Grav project with all the dependencies installed")
->setHelp("The <info>new-project</info> command is a combination of the `setup` and `install` commands.\nCreates a new Grav instance and performs the installation of all the required dependencies.");
->setDescription('Creates a new Grav project with all the dependencies installed')
->setHelp('The <info>new-project</info> command is a combination of the `setup` and `install` commands.\nCreates a new Grav instance and performs the installation of all the required dependencies.');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$sandboxCommand = $this->getApplication()->find('sandbox');
$installCommand = $this->getApplication()->find('install');
$sandboxArguments = new ArrayInput(array(
'command' => 'sandbox',
'destination' => $input->getArgument('destination'),
'-s' => $input->getOption('symlink')
'destination' => $this->input->getArgument('destination'),
'-s' => $this->input->getOption('symlink')
));
$installArguments = new ArrayInput(array(
'command' => 'install',
'destination' => $input->getArgument('destination'),
'-s' => $input->getOption('symlink')
'destination' => $this->input->getArgument('destination'),
'-s' => $this->input->getOption('symlink')
));
$sandboxCommand->run($sandboxArguments, $output);
$installCommand->run($installArguments, $output);
$sandboxCommand->run($sandboxArguments, $this->output);
$installCommand->run($installArguments, $this->output);
}
}

View File

@@ -1,48 +1,40 @@
<?php
namespace Grav\Console\Cli;
use Grav\Console\ConsoleCommand;
use Grav\Common\File\CompiledYamlFile;
use Grav\Common\User\User;
use Grav\Console\ConsoleTrait;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\Question;
/**
* Class CleanCommand
*
* @package Grav\Console\Cli
*/
class NewUserCommand extends Command
class NewUserCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* Configure the command
*/
protected function configure()
{
$this
->setName("newuser")
->setDescription("Creates a new user")
->setHelp('The <info>newuser</info> creates a new user file in user/accounts/ folder');
->setName('new-user')
->setAliases(['newuser'])
->setDescription('Creates a new user')
->setHelp('The <info>newuser</info> creates a new user file in user/accounts/ folder')
;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$helper = $this->getHelper('question');
$data = [];
$data = [];
$this->output->writeln('<green>Create new user</green>');
$this->output->writeln('');
@@ -51,13 +43,13 @@ class NewUserCommand extends Command
$question = new Question('Enter a <yellow>username</yellow>: ', 'admin');
$question->setValidator(function ($value) {
if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) {
throw new RuntimeException(
throw new \RuntimeException(
'Username should be between 3 and 16 characters, including lowercase letters, numbers, underscores, and hyphens. Uppercase letters, spaces, and special characters are not allowed'
);
}
if (file_exists(self::getGrav()['locator']->findResource('user://accounts/' . $value . YAML_EXT))) {
throw new RuntimeException(
'Username "'.$value.'" already exists, please pick another username'
throw new \RuntimeException(
'Username "' . $value . '" already exists, please pick another username'
);
}
return $value;
@@ -65,14 +57,14 @@ class NewUserCommand extends Command
$username = $helper->ask($this->input, $this->output, $question);
// Get password and validate
$password = $this->askForPassword($helper, 'Enter a <yellow>password</yellow>: ', function ($password1) use ($helper) {
$password = $this->askForPassword($helper, 'Enter a <yellow>password</yellow>: ', function ($password1) use ($helper) {
if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $password1)) {
throw new RuntimeException('Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters');
throw new \RuntimeException('Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters');
}
// Since input is hidden when prompting for passwords, the user is asked to repeat the password
return $this->askForPassword($helper, 'Repeat the <yellow>password</yellow>: ', function ($password2) use ($password1) {
if (strcmp($password2, $password1)) {
throw new RuntimeException('Passwords did not match.');
throw new \RuntimeException('Passwords did not match.');
}
return $password2;
});
@@ -83,7 +75,7 @@ class NewUserCommand extends Command
$question = new Question('Enter an <yellow>email</yellow>: ');
$question->setValidator(function ($value) {
if (!preg_match('/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/', $value)) {
throw new RuntimeException(
throw new \RuntimeException(
'Not a valid email address'
);
}
@@ -94,7 +86,7 @@ class NewUserCommand extends Command
// Choose permissions
$question = new ChoiceQuestion(
'Please choose a set of <yellow>permissions</yellow>:',
array('a'=>'admin access', 's'=>'site access', 'b'=>'admin and site access'),
array('a' => 'admin access', 's' => 'site access', 'b' => 'admin and site access'),
'a'
);
$question->setErrorMessage('permissions %s is invalid.');
@@ -109,14 +101,14 @@ class NewUserCommand extends Command
break;
case 'b':
$data['access']['admin'] = ['login' => true, 'super' => true];
$data['access']['site'] = ['login' => true];
$data['access']['site'] = ['login' => true];
}
// Get fullname
$question = new Question('Enter a <yellow>fullname</yellow>: ');
$question->setValidator(function ($value) {
if ($value === null || trim($value) == '') {
throw new RuntimeException(
throw new \RuntimeException(
'Fullname is required'
);
}
@@ -125,7 +117,7 @@ class NewUserCommand extends Command
$data['fullname'] = $helper->ask($this->input, $this->output, $question);
// Get title
$question = new Question('Enter a <yellow>title</yellow>: ');
$question = new Question('Enter a <yellow>title</yellow>: ');
$data['title'] = $helper->ask($this->input, $this->output, $question);
// Create user object and save it
@@ -135,15 +127,15 @@ class NewUserCommand extends Command
$user->save();
$this->output->writeln('');
$this->output->writeln('<green>Success!</green> User <cyan>'. $username .'</cyan> created.');
$this->output->writeln('<green>Success!</green> User <cyan>' . $username . '</cyan> created.');
}
/**
* Get password and validate.
*
* @param Helper $helper
* @param string $question
* @param callable $validator
* @param Helper $helper
* @param string $question
* @param callable $validator
*
* @return string
*/

View File

@@ -1,23 +1,17 @@
<?php
namespace Grav\Console\Cli;
use Grav\Console\ConsoleCommand;
use Grav\Common\Filesystem\Folder;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class SandboxCommand
* @package Grav\Console\Cli
*/
class SandboxCommand extends Command
class SandboxCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var array
*/
@@ -96,18 +90,14 @@ class SandboxCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->destination = $input->getArgument('destination');
$this->destination = $this->input->getArgument('destination');
// Symlink the Core Stuff
if ($input->getOption('symlink')) {
if ($this->input->getOption('symlink')) {
// Create Some core stuff if it doesn't exist
$this->createDirectories();

View File

@@ -0,0 +1,35 @@
<?php
namespace Grav\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class ConsoleCommand
*
* @package Grav\Console
*/
class ConsoleCommand extends Command
{
use ConsoleTrait;
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setupConsole($input, $output);
$this->serve();
}
/**
*
*/
protected function serve() { }
}

View File

@@ -2,20 +2,16 @@
namespace Grav\Console\Gpm;
use Grav\Common\GPM\GPM;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class IndexCommand
*
* @package Grav\Console\Gpm
*/
class IndexCommand extends Command
class IndexCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -39,19 +35,15 @@ class IndexCommand extends Command
'Force re-fetching the data from remote'
)
->setDescription("Lists the plugins and themes available for installation")
->setHelp('The <info>index</info> command lists the plugins and themes available for installation');
->setHelp('The <info>index</info> command lists the plugins and themes available for installation')
;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->gpm = new GPM($this->input->getOption('force'));
$this->data = $this->gpm->getRepository();
@@ -93,15 +85,15 @@ class IndexCommand extends Command
*/
private function versionDetails($package)
{
$list = $this->gpm->{'getUpdatable' . ucfirst($package->package_type)}();
$package = isset($list[$package->slug]) ? $list[$package->slug] : $package;
$type = ucfirst(preg_replace("/s$/", '', $package->package_type));
$list = $this->gpm->{'getUpdatable' . ucfirst($package->package_type)}();
$package = isset($list[$package->slug]) ? $list[$package->slug] : $package;
$type = ucfirst(preg_replace("/s$/", '', $package->package_type));
$updatable = $this->gpm->{'is' . $type . 'Updatable'}($package->slug);
$installed = $this->gpm->{'is' . $type . 'Installed'}($package->slug);
$local = $this->gpm->{'getInstalled' . $type}($package->slug);
$local = $this->gpm->{'getInstalled' . $type}($package->slug);
if (!$installed || !$updatable) {
$version = $installed ? $local->version : $package->version;
$version = $installed ? $local->version : $package->version;
$installed = !$installed ? ' (<magenta>not installed</magenta>)' : ' (<cyan>installed</cyan>)';
return str_pad(" [v<green>" . $version . "</green>]", 35) . $installed;

View File

@@ -2,21 +2,16 @@
namespace Grav\Console\Gpm;
use Grav\Common\GPM\GPM;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class InfoCommand
* @package Grav\Console\Gpm
*/
class InfoCommand extends Command
class InfoCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -49,20 +44,16 @@ class InfoCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->gpm = new GPM($this->input->getOption('force'));
$foundPackage = $this->gpm->findPackage($input->getArgument('package'));
$foundPackage = $this->gpm->findPackage($this->input->getArgument('package'));
if (!$foundPackage) {
$this->output->writeln("The package <cyan>'" . $input->getArgument('package') . "'</cyan> was not found in the Grav repository.");
$this->output->writeln("The package <cyan>'" . $this->input->getArgument('package') . "'</cyan> was not found in the Grav repository.");
$this->output->writeln('');
$this->output->writeln("You can list all the available packages by typing:");
$this->output->writeln(" <green>" . $this->argv . " index</green>");
@@ -70,7 +61,7 @@ class InfoCommand extends Command
exit;
}
$this->output->writeln("Found package <cyan>'" . $input->getArgument('package') . "'</cyan> under the '<green>" . ucfirst($foundPackage->package_type) . "</green>' section");
$this->output->writeln("Found package <cyan>'" . $this->input->getArgument('package') . "'</cyan> under the '<green>" . ucfirst($foundPackage->package_type) . "</green>' section");
$this->output->writeln('');
$this->output->writeln("<cyan>" . $foundPackage->name . "</cyan> [" . $foundPackage->slug . "]");
$this->output->writeln(str_repeat('-', strlen($foundPackage->name) + strlen($foundPackage->slug) + 3));

View File

@@ -5,14 +5,10 @@ use Grav\Common\Filesystem\Folder;
use Grav\Common\GPM\GPM;
use Grav\Common\GPM\Installer;
use Grav\Common\GPM\Response;
use Grav\Common\Inflector;
use Grav\Common\Utils;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Yaml\Yaml;
@@ -23,10 +19,8 @@ define('GIT_REGEX', '/http[s]?:\/\/(?:.*@)?(github|bitbucket)(?:.org|.com)\/.*\/
* Class InstallCommand
* @package Grav\Console\Gpm
*/
class InstallCommand extends Command
class InstallCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -87,15 +81,10 @@ class InstallCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->gpm = new GPM($this->input->getOption('force'));
$this->destination = realpath($this->input->getOption('destination'));

View File

@@ -5,22 +5,17 @@ use Grav\Common\Filesystem\Folder;
use Grav\Common\GPM\Installer;
use Grav\Common\GPM\Response;
use Grav\Common\GPM\Upgrader;
use Grav\Console\ConsoleTrait;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
/**
* Class SelfupgradeCommand
* @package Grav\Console\Gpm
*/
class SelfupgradeCommand extends Command
class SelfupgradeCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -75,14 +70,10 @@ class SelfupgradeCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->upgrader = new Upgrader($this->input->getOption('force'));
$update = $this->upgrader->getAssets()['grav-update'];

View File

@@ -3,22 +3,17 @@ namespace Grav\Console\Gpm;
use Grav\Common\GPM\GPM;
use Grav\Common\GPM\Installer;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
/**
* Class UninstallCommand
* @package Grav\Console\Gpm
*/
class UninstallCommand extends Command
class UninstallCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -63,15 +58,10 @@ class UninstallCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->gpm = new GPM();
$packages = array_map('strtolower', $this->input->getArgument('package'));

View File

@@ -3,23 +3,18 @@ namespace Grav\Console\Gpm;
use Grav\Common\GPM\GPM;
use Grav\Common\GPM\Installer;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
/**
* Class UpdateCommand
* @package Grav\Console\Gpm
*/
class UpdateCommand extends Command
class UpdateCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -85,15 +80,10 @@ class UpdateCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->gpm = new GPM($this->input->getOption('force'));
$this->destination = realpath($this->input->getOption('destination'));
$skip_prompt = $this->input->getOption('all-yes');

View File

@@ -3,21 +3,16 @@ namespace Grav\Console\Gpm;
use Grav\Common\GPM\GPM;
use Grav\Common\GPM\Upgrader;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Grav\Console\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class VersionCommand
* @package Grav\Console\Gpm
*/
class VersionCommand extends Command
class VersionCommand extends ConsoleCommand
{
use ConsoleTrait;
/**
* @var
*/
@@ -46,15 +41,10 @@ class VersionCommand extends Command
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function serve()
{
$this->setupConsole($input, $output);
$this->gpm = new GPM($this->input->getOption('force'));
$packages = $this->input->getArgument('package');