Skip to content

Commit

Permalink
feat: allow tools based on this one to override the default prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Apr 26, 2023
1 parent a2504ed commit 4794690
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Command/Command.php
Expand Up @@ -197,7 +197,7 @@ private function buildComposerExtraConfiguration(): ExtraConfiguration

$commandPrefix = $config['command-prefix']
?? $extra['command-prefix']
?? ExtraConfiguration::DEFAULT_COMMAND_PREFIX;
?? $this->configuration->composerDefaultCommandPrefix;

return new ExtraConfiguration(
commandName: (string) $this->getName(),
Expand Down
4 changes: 1 addition & 3 deletions src/Composer/ExtraConfiguration.php
Expand Up @@ -41,8 +41,6 @@
*/
final class ExtraConfiguration
{
public const DEFAULT_COMMAND_PREFIX = 'dev';

/**
* @link https://getcomposer.org/doc/articles/scripts.md#writing-custom-commands Composer's custom commands
* @link https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes PHP's shorthand bytes options
Expand All @@ -62,7 +60,7 @@ final class ExtraConfiguration
*/
public function __construct(
public readonly string $commandName,
public readonly string $commandPrefix = self::DEFAULT_COMMAND_PREFIX,
public readonly string $commandPrefix,
public readonly array $scripts = [],
public readonly bool $override = false,
public readonly int | string | null $memoryLimit = null,
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.php
Expand Up @@ -28,6 +28,7 @@
final class Configuration
{
public const EXTRA_PROPERTY = 'ramsey/devtools';
public const DEFAULT_COMMAND_PREFIX = 'dev';

public readonly Composer $composer;
public readonly string $composerBinDir;
Expand All @@ -44,6 +45,7 @@ public function __construct(
public readonly ProcessFactory $processFactory = new ProcessFactory(),
public readonly Filesystem $filesystem = new Filesystem(),
public readonly string $composerExtraProperty = self::EXTRA_PROPERTY,
public readonly string $composerDefaultCommandPrefix = self::DEFAULT_COMMAND_PREFIX,
) {
$this->composer = $this->composerFactory->getComposer();
$this->composerBinDir = $this->getComposerBinDir();
Expand Down
6 changes: 3 additions & 3 deletions tests/Composer/ExtraConfigurationTest.php
Expand Up @@ -12,14 +12,14 @@ class ExtraConfigurationTest extends TestCase
{
public function testDefaults(): void
{
$extra = new ExtraConfiguration('foobar');
$extra = new ExtraConfiguration('foobar', 'cmd');

$this->assertSame('foobar', $extra->commandName);
$this->assertSame('dev', $extra->commandPrefix);
$this->assertSame('cmd', $extra->commandPrefix);
$this->assertSame([], $extra->scripts);
$this->assertFalse($extra->override);
$this->assertNull($extra->memoryLimit);
$this->assertSame('dev:foobar', $extra->getPrefixedCommandName());
$this->assertSame('cmd:foobar', $extra->getPrefixedCommandName());
}

#[TestWith(['', 'foobar'])]
Expand Down
1 change: 1 addition & 0 deletions tests/ConfigurationTest.php
Expand Up @@ -44,5 +44,6 @@ public function testConstructorSetsDefaultValues(): void
$configuration->execPath,
);
$this->assertSame('ramsey/devtools', $configuration->composerExtraProperty);
$this->assertSame('dev', $configuration->composerDefaultCommandPrefix);
}
}

0 comments on commit 4794690

Please sign in to comment.