57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace NoccyLabs\Composer\PackagePlugin\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Composer\Command\BaseCommand;
|
|
use NoccyLabs\Composer\PackagePlugin\Package\PackagePublisher;
|
|
use NoccyLabs\Composer\PackagePlugin\Project\ProjectInfo;
|
|
use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\InsecureStore;
|
|
use NoccyLabs\Composer\PackagePlugin\Registry\Gitea\GiteaProvider;
|
|
use NoccyLabs\Composer\PackagePlugin\Registry\RegistryFactory;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
class PackagePublishCommand extends BaseCommand
|
|
{
|
|
protected function configure(): void
|
|
{
|
|
$this
|
|
->setName('package:publish')
|
|
->setDescription("Publish a package to a composer package registry")
|
|
->addArgument("registry", InputArgument::OPTIONAL, "The registry to publish to")
|
|
;
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$credentials = new InsecureStore();
|
|
|
|
$providers = [
|
|
'gitea' => new GiteaProvider($credentials)
|
|
];
|
|
|
|
$registry = new RegistryFactory($providers);
|
|
$publisher = new PackagePublisher($registry, $output);
|
|
|
|
$project = ProjectInfo::read();
|
|
|
|
$registry = $input->getArgument("registry");
|
|
if (!$registry) {
|
|
$output->writeln([
|
|
"Missing registry to publish to. Please specify the registry like this:",
|
|
"",
|
|
" <info>gitea:<server></> - to publish to <info>server</> as the default user",
|
|
" <info>gitea:<server>/<owner></> - to publish to <info>server</> as <info>owner</>",
|
|
""
|
|
]);
|
|
return self::INVALID;
|
|
}
|
|
|
|
$publisher->publish($project, $registry);
|
|
|
|
|
|
return 0;
|
|
}
|
|
}
|