php-hotfix/src/Command/SignCommand.php

49 lines
1.3 KiB
PHP

<?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 NoccyLabs\Hotfix\Hotfix\Loader;
class SignCommand extends Command
{
protected function configure()
{
$this->setName("sign");
$this->setDescription("Sign and bundle a hotfix");
$this->addOption("signer", "s", InputOption::VALUE_REQUIRED, "Signer e-mail");
$this->addArgument("hotfix", InputArgument::OPTIONAL, "The filename of the hotfix to sign");
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$fix = $input->getArgument("hotfix");
$signer = $input->getOption("signer");
$cmdl = 'gpg --sign --armour --detach';
if ($signer) {
$cmdl.= ' --default-key '.$signer;
}
$cmdl.= ' '.escapeshellarg($fix);
passthru($cmdl);
$out = $fix.".signed";
file_put_contents($out,
file_get_contents($fix).
file_get_contents($fix.'.asc')
);
unlink($fix.'.asc');
}
}