Skip to content

Commit

Permalink
#10 Make the <version> cli parameter optional (#56)
Browse files Browse the repository at this point in the history
* #10 Make the <version> cli parameter optional
Co-authored-by: Jonas Renaudot <jonas.renaudot@gmail.com>
  • Loading branch information
LeJeanbono authored Oct 13, 2021
1 parent 9ce4076 commit 685b40c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Many of the options are optional since they can be added directly to the `compos
[--ssl-verify=true/]\
[--access-token=<ACCESS_TOKEN added in Bearer>]
<version>

If <version> is not set, `composer.json` version will be used.

# Example
$ composer push --username=admin --password=admin123 --url=http://localhost:8081/repository/composer --ignore=test.php --ignore=foo/ --src-type=git --src-url="$(git remote get-url origin)" --src-ref="$(git rev-parse HEAD)" 0.0.1
Expand Down
4 changes: 3 additions & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ public function getUrl()

/**
* Return the package version
* If version argument is not set, will return composer.json version property
* @return string
*/
public function getVersion()
{
return $this->input->getArgument('version');
$versionArgument = $this->input->getArgument('version');
return empty($versionArgument) ? $this->composer->getPackage()->getVersion() : $versionArgument;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function configure()
->setAliases(['nexus-push']) // Deprecated, use push instead
->setDescription('Initiate a push to a distant repository')
->setDefinition([
new InputArgument('version', InputArgument::REQUIRED, 'The package version'),
new InputArgument('version', InputArgument::OPTIONAL, 'The package version, if not set take composer.json version'),
new InputOption('name', null, InputArgument::OPTIONAL, 'Name of the package (if different from the composer.json file)'),
new InputOption('url', null, InputArgument::OPTIONAL, 'URL to the distant repository'),
new InputOption('type', null, InputArgument::OPTIONAL, 'Type of the distant repository (default: nexus, available: [' . implode(', ', array_keys(self::PROVIDER_TYPES)) . '])'),
Expand Down
22 changes: 16 additions & 6 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,24 @@ public function setUp(): void

public function testGetVersion()
{
$this->inputMock->method('getArgument')->willReturnCallback(function ($argument) {
if ($argument === 'version') {
return '1.0.1';
}
});
$this->assertEquals('1.0.1', $this->configuration->getVersion());
}

public function testGetVersionComposeJson()
{
$this->inputMock->method('getArgument')->willReturnCallback(function ($argument) {
if ($argument === 'version') {
return null;
}
});
$this->assertEquals('1.2.3', $this->configuration->getVersion());
}

public function testGetSourceUrl()
{
$this->assertEquals('my-src-url', $this->configuration->getSourceUrl());
Expand Down Expand Up @@ -277,12 +292,6 @@ private function createInputMock()
}
});

$input->method('getArgument')->willReturnCallback(function ($argument) {
if ($argument === 'version') {
return '1.0.1';
}
});

return $input;
}

Expand All @@ -300,6 +309,7 @@ private function createComposerMock()

$composer->method('getPackage')->willReturn($packageInterface);

$packageInterface->method('getVersion')->willReturn('1.2.3');
$packageInterface->method('getExtra')->willReturnCallback(function() {
if ($this->singleConfig) {
return [
Expand Down

0 comments on commit 685b40c

Please sign in to comment.