Initial commit
This commit is contained in:
76
src/Command/ApplyCommand.php
Normal file
76
src/Command/ApplyCommand.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Hotfix\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use NoccyLabs\Hotfix\Hotfix\Loader;
|
||||
|
||||
class ApplyCommand extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName("apply");
|
||||
$this->setDescription("Apply a hotfix from a file or the Internet");
|
||||
|
||||
$this->addOption("insecure", "I", InputOption::VALUE_NONE, "Disable signature checks. Don't use unless you know what you are doing!");
|
||||
|
||||
$this->addArgument("hotfix", InputArgument::OPTIONAL, "The identifier, path or filename of the hotfix");
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
|
||||
$fix = $input->getArgument("hotfix");
|
||||
$insecure = $input->getOption("insecure");
|
||||
|
||||
$output->writeln("Reading hotfix <comment>{$fix}</comment>...");
|
||||
|
||||
$loader = new Loader();
|
||||
try {
|
||||
$hotfix = $loader->load($fix, $insecure);
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>Error: ".$e->getMessage()."</error>");
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeln("");
|
||||
if (($signer = $hotfix->getSignedBy())) {
|
||||
$output->writeln("<info>Hotfix has good signature by {$signer}</info>");
|
||||
} else {
|
||||
$output->writeln("<fg=red;options=bold>Warning: Hotfix is not signed or signature not valid!</fg=red;options=bold>");
|
||||
}
|
||||
$output->writeln("");
|
||||
$output->writeln(" Hotfix: <comment>".$hotfix->getName()."</comment>");
|
||||
$output->writeln(" Author: <comment>".$hotfix->getAuthor()."</comment>");
|
||||
$output->writeln(" Info:");
|
||||
$info = explode("\n",wordwrap(trim($hotfix->getInfo()), 70));
|
||||
foreach ($info as $line) {
|
||||
$output->writeln(" | <info>{$line}</info>");
|
||||
}
|
||||
$output->writeln("");
|
||||
|
||||
$helper = $this->getHelper("question");
|
||||
$question = new ConfirmationQuestion("Do you want to apply this hotfix? [y/N] ", false);
|
||||
|
||||
if (!$helper->ask($input, $output, $question)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeln("\n<info>Applying hotfix...</info>\n");
|
||||
try {
|
||||
$hotfix->apply();
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("\n<error>Error: ".$e->getMessage()."</error>");
|
||||
}
|
||||
$output->writeln("\n<info>Hotfix applied successfully</info>");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user