Skip to content

Commit

Permalink
Creates a Copy Command (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes authored Oct 24, 2023
1 parent 0e1c118 commit bd02200
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/bard/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ bard release patch

Bard will track the versions so you can just use the keywords: major, minor,
patch.

Copy the LICENSE file from the root to all packages
```shell
bard copy LICENSE
```
1 change: 1 addition & 0 deletions src/SonsOfPHP/Bard/src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected function getDefaultCommands(): array
{
return array_merge(parent::getDefaultCommands(), [
new \SonsOfPHP\Bard\Console\Command\AddCommand(),
new \SonsOfPHP\Bard\Console\Command\CopyCommand(),
new \SonsOfPHP\Bard\Console\Command\InitCommand(),
new \SonsOfPHP\Bard\Console\Command\InstallCommand(),
new \SonsOfPHP\Bard\Console\Command\MergeCommand(),
Expand Down
48 changes: 48 additions & 0 deletions src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Bard\Console\Command;

use SonsOfPHP\Bard\JsonFile;
use Symfony\Component\Console\Input\InputArgument;
use SonsOfPHP\Component\Json\Json;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\Process;

/**
* @author Joshua Estes <joshua@sonsofphp.com>
*/
final class CopyCommand extends AbstractCommand
{
protected static $defaultName = 'copy';

protected function configure(): void
{
$this
->setDescription('Copies a file to each package')
->addArgument('source', InputArgument::REQUIRED, 'Source file to copy')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$sourceFile = $input->getOption('working-dir') . '/' . $input->getArgument('source');
if (!is_file($sourceFile)) {
throw new \RuntimeException(sprintf('The file "%s" is an invalid file.', $sourceFile));
}
$bardJsonFile = new JsonFile($input->getOption('working-dir') . '/bard.json');
foreach ($bardJsonFile->getSection('packages') as $pkg) {
$process = new Process(['cp', $sourceFile, $pkg['path']]);
$io->text($process->getCommandLine());
$this->getHelper('process')->run($output, $process);

Check failure on line 41 in src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php

View workflow job for this annotation

GitHub Actions / Psalm (8.1)

UndefinedInterfaceMethod

src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php:41:42: UndefinedInterfaceMethod: Method Symfony\Component\Console\Helper\HelperInterface::run does not exist (see https://psalm.dev/181)
}

$io->success('File has been copied.');

return self::SUCCESS;
}
}

0 comments on commit bd02200

Please sign in to comment.