Improvements

This commit is contained in:
Christopher Vagnetoft
2016-04-19 22:55:09 +02:00
parent fceb4c4966
commit b63260533f
12 changed files with 101 additions and 13 deletions

View File

@ -9,6 +9,7 @@ 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 Symfony\Component\Console\Question\ChoiceQuestion;
use NoccyLabs\Hotfix\Hotfix\Loader;
class ApplyCommand extends Command
@ -20,6 +21,7 @@ class ApplyCommand extends Command
$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->addOption("preview", "p", InputOption::VALUE_NONE, "Only preview the hotfix script, don't apply anything");
$this->addArgument("hotfix", InputArgument::OPTIONAL, "The identifier, path or filename of the hotfix");
}
@ -30,10 +32,20 @@ class ApplyCommand extends Command
$fix = $input->getArgument("hotfix");
$insecure = $input->getOption("insecure");
$loader = new Loader();
if (!$fix) {
$loaders = $loader->getLoaders();
$output->writeln("Supported loaders:\n");
foreach ($loaders as $loader) {
$output->writeln(" * ".$loader->getInfo());
}
return;
}
$output->writeln("Reading hotfix <comment>{$fix}</comment>...");
$loader = new Loader();
try {
$hotfix = $loader->load($fix, $insecure);
} catch (\Exception $e) {
@ -47,20 +59,27 @@ class ApplyCommand extends Command
$output->writeln("");
if (($signer = $hotfix->getSignedBy())) {
$output->writeln("<info>Hotfix has good signature by {$signer}</info>");
$keyid = $hotfix->getKeyId();
$output->writeln("Hotfix has good signature from <fg=green;options=bold>{$signer}</fg=green;options=bold> (keyid <info>{$keyid}</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(" Hotfix: <fg=yellow;options=bold>".$hotfix->getName()."</fg=yellow;options=bold>");
$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>");
}
$info = explode("\n",wordwrap(trim($hotfix->getInfo()), 60));
$info = "<comment>".join("</comment>\n <comment>", $info)."</comment>";
$output->writeln(" Info: ".$info);
$output->writeln("");
if ($input->getOption("preview")) {
$output->writeln("This is the script that will be executed:");
$body = $hotfix->getBody();
$body = "<fg=cyan> ".join("\n ", explode("\n",$body))."</fg=cyan>";
$output->writeln($body);
return;
}
$helper = $this->getHelper("question");
$question = new ConfirmationQuestion("Do you want to apply this hotfix? [y/N] ", false);