-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from asgrim/use-repo-commands
Add repository management commands
- Loading branch information
Showing
19 changed files
with
979 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<title>PIE Documentation</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/themes/prism.css" rel="stylesheet" /> | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" rel="stylesheet" /> | ||
<style> | ||
.selected { | ||
background-color: #7A86B8; | ||
|
@@ -15,6 +17,41 @@ | |
.hidden { | ||
display: none; | ||
} | ||
.markdown-alert { | ||
border-left: 0.25em solid black; | ||
padding: 1em 1em 0.25em; | ||
background-color: #f7f7f7; | ||
} | ||
.markdown-alert-note { | ||
border-left-color: #0d68d5; | ||
} | ||
.markdown-alert-note .markdown-alert-title { | ||
color: #0d68d5; | ||
} | ||
.markdown-alert-tip { | ||
border-left-color: #188337; | ||
} | ||
.markdown-alert-tip .markdown-alert-title { | ||
color: #188337; | ||
} | ||
.markdown-alert-important { | ||
border-left-color: #7844d6; | ||
} | ||
.markdown-alert-important .markdown-alert-title { | ||
color: #7844d6; | ||
} | ||
.markdown-alert-warning { | ||
border-left-color: #a67003; | ||
} | ||
.markdown-alert-warning .markdown-alert-title { | ||
color: #a67003; | ||
} | ||
.markdown-alert-caution { | ||
border-left-color: #d61c28; | ||
} | ||
.markdown-alert-caution .markdown-alert-title { | ||
color: #d61c28; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
@@ -47,6 +84,10 @@ | |
* @param {string} title | ||
*/ | ||
function loadDocBookNavigation(title) { | ||
document.querySelectorAll('table').forEach((table) => { | ||
table.classList.add("table"); | ||
}) | ||
/** | ||
* @param {NodeListOf<HTMLElement>} unselectedListElements | ||
* @param {HTMLElement} selectedListElement | ||
|
@@ -184,5 +225,7 @@ | |
loadDocBookNavigation("PIE Documentation"); | ||
</script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Feature: Package repositories can be managed with PIE | ||
|
||
Example: A package repository can be added | ||
Given no repositories have previously been added | ||
When I add a package repository | ||
Then I should see the package repository can be used by PIE | ||
|
||
Example: A package repository can be removed | ||
Given I have previously added a package repository | ||
When I remove the package repository | ||
Then I should see the package repository is not used by PIE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Php\Pie\Command; | ||
|
||
use Php\Pie\ComposerIntegration\PieComposerFactory; | ||
use Php\Pie\ComposerIntegration\PieComposerRequest; | ||
use Php\Pie\ComposerIntegration\PieJsonEditor; | ||
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
use function realpath; | ||
use function str_contains; | ||
|
||
#[AsCommand( | ||
name: 'repository:add', | ||
description: 'Add a new repository for packages that PIE can use.', | ||
)] | ||
final class RepositoryAddCommand extends Command | ||
{ | ||
private const ARG_TYPE = 'type'; | ||
private const ARG_URL = 'url'; | ||
|
||
private const ALLOWED_TYPES = ['vcs', 'path', 'composer']; | ||
|
||
public function __construct( | ||
private readonly ContainerInterface $container, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function configure(): void | ||
{ | ||
parent::configure(); | ||
|
||
CommandHelper::configurePhpConfigOptions($this); | ||
|
||
$this->addArgument( | ||
self::ARG_TYPE, | ||
InputArgument::REQUIRED, | ||
'Specify the type of the repository, e.g. vcs, path, composer', | ||
); | ||
$this->addArgument( | ||
self::ARG_URL, | ||
InputArgument::REQUIRED, | ||
'Specify the URL of the repository, e.g. a Github/Gitlab URL, a filesystem path, or Private Packagist URL', | ||
); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); | ||
$pieJsonEditor = PieJsonEditor::fromTargetPlatform($targetPlatform); | ||
|
||
$type = (string) $input->getArgument(self::ARG_TYPE); | ||
/** @psalm-var 'vcs'|'path'|'composer' $type */ | ||
Assert::inArray($type, self::ALLOWED_TYPES); | ||
|
||
$url = $originalUrl = (string) $input->getArgument(self::ARG_URL); | ||
|
||
if ($type === 'path') { | ||
$url = realpath($originalUrl); | ||
} | ||
|
||
if ($type === 'composer' && str_contains($url, 'packagist.org')) { | ||
// "adding packagist" is really just removing an exclusion | ||
$pieJsonEditor | ||
->ensureExists() | ||
->removeRepository('packagist.org'); | ||
} else { | ||
Assert::stringNotEmpty($url, 'Could not resolve ' . $originalUrl . ' to a real path'); | ||
|
||
$pieJsonEditor | ||
->ensureExists() | ||
->addRepository($type, $url); | ||
} | ||
|
||
CommandHelper::listRepositories( | ||
PieComposerFactory::createPieComposer( | ||
$this->container, | ||
PieComposerRequest::noOperation( | ||
$output, | ||
$targetPlatform, | ||
), | ||
), | ||
$output, | ||
); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Php\Pie\Command; | ||
|
||
use Php\Pie\ComposerIntegration\PieComposerFactory; | ||
use Php\Pie\ComposerIntegration\PieComposerRequest; | ||
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand( | ||
name: 'repository:list', | ||
description: 'List the package repositories that PIE uses.', | ||
)] | ||
final class RepositoryListCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly ContainerInterface $container, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function configure(): void | ||
{ | ||
parent::configure(); | ||
|
||
CommandHelper::configurePhpConfigOptions($this); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
CommandHelper::listRepositories( | ||
PieComposerFactory::createPieComposer( | ||
$this->container, | ||
PieComposerRequest::noOperation( | ||
$output, | ||
CommandHelper::determineTargetPlatformFromInputs($input, $output), | ||
), | ||
), | ||
$output, | ||
); | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.