Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

#10 Make the <version> cli parameter optional #56

Merged
merged 3 commits into from
Oct 13, 2021
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
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