Skip to content

Support custom XML config #6

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,54 @@ composer require internal/dload -W
./vendor/bin/dload get dolt
```

### Configure preset for the project (WIP)
### Configure preset for the project

Create `dload.xml` file in the root of the project with the following content:

```xml
<?xml version="1.0"?>
<dload>
<todo />
<actions>
<download software="rr" version="^2.12.0" />
<download software="temporal"/>
</actions>
</dload>
```

Download all the software from the preset:
There are two software packages to download: `temporal` and `rr` with version `^2.12.0`.
Optionally, you may specify the version of the software package using Composer versioning syntax.
To download all the configured software, run `dload get` without arguments:

```bash
./vendor/bin/dload get
```

### Custom software registry

```xml
<?xml version="1.0"?>
<dload>
<registry>
<software name="RoadRunner"
alias="rr"
description="High performant Application server"
>
<repository type="github"
uri="roadrunner-server/roadrunner"
asset-pattern="/^roadrunner-.*/"
/>
<file pattern="/^(roadrunner|rr)(?:\.exe)?$/"
rename="rr"
/>
</software>
</registry>
</dload>
```

### GitHub Token

To increase the rate limit for GitHub API, you can specify the token in the environment variable `GITHUB_TOKEN`:

```bash
GITHUB_TOKEN=your_token_here ./vendor/bin/dload get
```
24 changes: 13 additions & 11 deletions dload.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?xml version="1.0"?>
<dload>
<registry>
<software name="RoadRunner" alias="rr" description="High performant Application server">
<!-- Example -->
<dload
temp-dir="./runtime"
>
<actions>
<download software="rr" version="^2.12.0" />
<download software="dolt" />
<download software="temporal" />
</actions>
<registry overwrite="false">
<software name="RoadRunner" alias="rr"
homepage="https://roadrunner.dev"
description="High performant Application server">
<repository type="github" uri="roadrunner-server/roadrunner" asset-pattern="/^roadrunner-.*/"/>
<file rename="rr" pattern="/^(roadrunner|rr)(?:\.exe)?$/" />
</software>
<software name="Dolt" description="Dolt is a SQL database that you can fork, clone, branch, merge, push and pull just like a Git repository">
<repository type="github" uri="dolthub/dolt" asset-pattern="/^dolt-.*/"/>
<file pattern="/^(dolt)(?:\.exe)?$/" />
</software>
<software name="Temporal" description="Temporal command-line interface and development server">
<repository type="github" uri="temporalio/cli" asset-pattern="/^temporal_cli_.*/"/>
<file pattern="/^(temporal)(?:\.exe)?$/" />
</software>
</registry>
</dload>
103 changes: 95 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
<file src="src/Command/Base.php">
<LessSpecificReturnStatement>
<code><![CDATA[$config]]></code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[non-empty-string|null]]></code>
</MoreSpecificReturnType>
</file>
<file src="src/Command/Get.php">
<ArgumentTypeCoercion>
<code><![CDATA[(string) $software]]></code>
</ArgumentTypeCoercion>
<LessSpecificReturnStatement>
<code><![CDATA[\array_map(
static fn(mixed $software): DownloadConfig => $toDownload[$software]
?? DownloadConfig::fromSoftwareId((string) $software),
$input->getArgument(self::ARG_SOFTWARE),
)]]></code>
</LessSpecificReturnStatement>
<MixedArgument>
<code><![CDATA[$binary]]></code>
<code><![CDATA[$input->getArgument(self::ARG_SOFTWARE)]]></code>
</MixedArgument>
<MixedArrayOffset>
<code><![CDATA[$toDownload[$software]]]></code>
</MixedArrayOffset>
<MixedAssignment>
<code><![CDATA[$binary]]></code>
<code><![CDATA[$argument]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$input->getArgument('binary')]]></code>
<code><![CDATA[$input->getOption('path')]]></code>
</MixedOperand>
<MoreSpecificReturnType>
<code><![CDATA[list<DownloadConfig>]]></code>
</MoreSpecificReturnType>
<PropertyNotSetInConstructor>
<code><![CDATA[$container]]></code>
<code><![CDATA[$logger]]></code>
<code><![CDATA[Get]]></code>
<code><![CDATA[Get]]></code>
</PropertyNotSetInConstructor>
<UndefinedThisPropertyAssignment>
<code><![CDATA[$this->cancelling]]></code>
</UndefinedThisPropertyAssignment>
</file>
<file src="src/Command/ListSoftware.php">
<MixedAssignment>
<code><![CDATA[$repo]]></code>
</MixedAssignment>
<MixedPropertyFetch>
<code><![CDATA[$repo->type]]></code>
<code><![CDATA[$repo->uri]]></code>
</MixedPropertyFetch>
<PropertyNotSetInConstructor>
<code><![CDATA[ListSoftware]]></code>
<code><![CDATA[ListSoftware]]></code>
</PropertyNotSetInConstructor>
<RawObjectIteration>
<code><![CDATA[$software->repositories]]></code>
</RawObjectIteration>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$software->homepage]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/DLoad.php">
<ArgumentTypeCoercion>
<code><![CDATA[$conf->pattern]]></code>
</ArgumentTypeCoercion>
<InvalidArgument>
<code><![CDATA[$software->files]]></code>
</InvalidArgument>
</file>
<file src="src/Module/Archive/ArchiveFactory.php">
<MixedPropertyTypeCoercion>
Expand All @@ -34,12 +79,33 @@
<code><![CDATA[\Generator]]></code>
</MoreSpecificReturnType>
</file>
<file src="src/Module/Common/Config/Action/Download.php">
<MissingConstructor>
<code><![CDATA[$software]]></code>
</MissingConstructor>
</file>
<file src="src/Module/Common/Config/Embed/Repository.php">
<MissingConstructor>
<code><![CDATA[$uri]]></code>
</MissingConstructor>
</file>
<file src="src/Module/Common/Config/Embed/Software.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[[]]]></code>
<code><![CDATA[[]]]></code>
<code><![CDATA[\array_map(
static fn(array $fileArray): File => File::fromArray($fileArray),
$softwareArray['files'] ?? [],
)]]></code>
<code><![CDATA[\array_map(
static fn(array $repositoryArray): Repository => Repository::fromArray($repositoryArray),
$softwareArray['repositories'] ?? [],
)]]></code>
</InvalidPropertyAssignmentValue>
<MismatchingDocblockPropertyType>
<code><![CDATA[array]]></code>
<code><![CDATA[array]]></code>
</MismatchingDocblockPropertyType>
<MissingConstructor>
<code><![CDATA[$name]]></code>
</MissingConstructor>
Expand Down Expand Up @@ -69,17 +135,29 @@
<ArgumentTypeCoercion>
<code><![CDATA[$context->repoConfig->assetPattern]]></code>
</ArgumentTypeCoercion>
<DocblockTypeContradiction>
<code><![CDATA[$repositories === []]]></code>
</DocblockTypeContradiction>
<InternalMethod>
<code><![CDATA[toArray]]></code>
<code><![CDATA[toArray]]></code>
</InternalMethod>
<InvalidArgument>
<code><![CDATA[$repositories]]></code>
</InvalidArgument>
<InvalidNullableReturnType>
<code><![CDATA[AssetInterface]]></code>
<code><![CDATA[ReleaseInterface]]></code>
</InvalidNullableReturnType>
<MissingClosureReturnType>
<code><![CDATA[static fn(int $dlNow, int $dlSize, array $info) => ($context->onProgress)(]]></code>
</MissingClosureReturnType>
<MixedArgument>
<code><![CDATA[$context->repoConfig]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$context->repoConfig]]></code>
</MixedAssignment>
<TooManyArguments>
<code><![CDATA[download]]></code>
</TooManyArguments>
Expand All @@ -92,6 +170,15 @@
<code><![CDATA[$repoConfig]]></code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Module/Downloader/SoftwareCollection.php">
<MixedArgument>
<code><![CDATA[$softwareArray]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$json]]></code>
<code><![CDATA[$softwareArray]]></code>
</MixedAssignment>
</file>
<file src="src/Module/Repository/Collection/ReleasesCollection.php">
<LessSpecificReturnStatement>
<code><![CDATA[\ltrim(\str_replace(
Expand Down
57 changes: 57 additions & 0 deletions resources/software.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"name": "RoadRunner",
"alias": "rr",
"homepage": "https://roadrunner.dev",
"description": "High-performance PHP application server, load-balancer and process manager written in Golang",
"repositories": [
{
"type": "github",
"uri": "roadrunner-server/roadrunner",
"asset-pattern": "/^roadrunner-.*/"
}
],
"files": [
{
"pattern": "/^(roadrunner|rr)(?:\\.exe)?$/",
"rename": "rr"
}
]
},
{
"name": "Temporal",
"alias": "temporal",
"description": "Temporal SDK",
"homepage": "https://temporal.io",
"repositories": [
{
"type": "github",
"uri": "temporalio/cli",
"asset-pattern": "/^temporal_cli_.*/"
}
],
"files": [
{
"pattern": "/^(temporal)(?:\\.exe)?$/"
}
]
},
{
"name": "Dolt",
"alias": "dolt",
"description": "Dolt is a SQL database that you can fork, clone, branch, merge, push and pull just like a git repository.",
"homepage": "https://www.dolthub.com",
"repositories": [
{
"type": "github",
"uri": "dolthub/dolt",
"asset-pattern": "/^dolt-.*/"
}
],
"files": [
{
"pattern": "/^(dolt)(?:\\.exe)?$/"
}
]
}
]
31 changes: 30 additions & 1 deletion src/Command/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Internal\DLoad\Service\Logger;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\StyleInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand All @@ -22,22 +23,50 @@ abstract class Base extends Command

protected Container $container;

public function configure(): void
{
parent::configure();
$this->addOption('config', null, InputOption::VALUE_OPTIONAL, 'Path to the configuration file');
}

protected function execute(
InputInterface $input,
OutputInterface $output,
): int {
$this->logger = new Logger($output);
$this->container = $container = Bootstrap::init()->withConfig(
xml: \dirname(__DIR__, 2) . '/dload.xml',
xml: $this->getConfigFile($input),
inputOptions: $input->getOptions(),
inputArguments: $input->getArguments(),
environment: \getenv(),
)->finish();

$container->set($input, InputInterface::class);
$container->set($output, OutputInterface::class);
$container->set(new SymfonyStyle($input, $output), StyleInterface::class);
$container->set($this->logger);

return Command::SUCCESS;
}

/**
* @return non-empty-string|null Path to the configuration file
*/
private function getConfigFile(InputInterface $input): ?string
{
/** @var string|null $config */
$config = $input->getOption('config');
$isConfigured = $config !== null;
$config ??= './dload.xml';

if (\is_file($config)) {
return $config;
}

$isConfigured and throw new \InvalidArgumentException(
'Configuration file not found: ' . $config,
);

return null;
}
}
Loading
Loading