Skip to content

Commit 0bb386a

Browse files
committed
add support for base and target arguments which can be interchanged with -b and -t options
1 parent 7c31597 commit 0bb386a

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ composer diff # Displays packages changed in current git tree compared with HEAD
7272
## Advanced usage
7373

7474
```shell script
75-
composer diff -b master:composer.lock -t develop:composer.lock -p # Compare master and develop branches, including platform dependencies
75+
composer diff master # Compare current composer.lock with the one on master branch
76+
composer diff master:composer.lock develop:composer.lock -p # Compare master and develop branches, including platform dependencies
7677
composer diff --no-dev # ignore dev dependencies
7778
composer diff -p # include platform dependencies
7879
composer diff -f json # Output as JSON instead of table

src/Command/DiffCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use IonBazan\ComposerDiff\Formatter\MarkdownTableFormatter;
1010
use IonBazan\ComposerDiff\PackageDiff;
1111
use IonBazan\ComposerDiff\Url\GeneratorContainer;
12+
use Symfony\Component\Console\Input\InputArgument;
1213
use Symfony\Component\Console\Input\InputInterface;
1314
use Symfony\Component\Console\Input\InputOption;
1415
use Symfony\Component\Console\Output\OutputInterface;
@@ -43,6 +44,8 @@ protected function configure()
4344
{
4445
$this->setName('diff')
4546
->setDescription('Displays package diff')
47+
->addArgument('base', InputArgument::OPTIONAL, 'Base composer.lock file path or git ref')
48+
->addArgument('target', InputArgument::OPTIONAL, 'Target composer.lock file path or git ref')
4649
->addOption('base', 'b', InputOption::VALUE_REQUIRED, 'Base composer.lock file path or git ref', 'HEAD:composer.lock')
4750
->addOption('target', 't', InputOption::VALUE_REQUIRED, 'Target composer.lock file path or git ref', 'composer.lock')
4851
->addOption('no-dev', null, InputOption::VALUE_NONE, 'Ignore dev dependencies')
@@ -59,8 +62,8 @@ protected function configure()
5962
*/
6063
protected function execute(InputInterface $input, OutputInterface $output)
6164
{
62-
$base = $input->getOption('base');
63-
$target = $input->getOption('target');
65+
$base = $input->getArgument('base') !== null ? $input->getArgument('base') : $input->getOption('base');
66+
$target = $input->getArgument('target') !== null ? $input->getArgument('target') :$input->getOption('target');
6467
$withPlatform = $input->getOption('with-platform');
6568
$withUrls = $input->getOption('with-links');
6669
$this->gitlabDomains = array_merge($this->gitlabDomains, $input->getOption('gitlab-domains'));

tests/Integration/DiffCommandTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ public function commandArgumentsDataProvider()
8787
'--no-dev' => null,
8888
),
8989
),
90+
'no-dev with arguments' => array(
91+
<<<OUTPUT
92+
| Prod Packages | Operation | Base | Target |
93+
|------------------------------------|-----------|---------|---------|
94+
| psr/event-dispatcher | New | - | 1.0.0 |
95+
| symfony/deprecation-contracts | New | - | v2.1.2 |
96+
| symfony/event-dispatcher | Upgraded | v2.8.52 | v5.1.2 |
97+
| symfony/event-dispatcher-contracts | New | - | v2.1.2 |
98+
| symfony/polyfill-php80 | New | - | v1.17.1 |
99+
100+
101+
OUTPUT
102+
,
103+
array(
104+
'base' => __DIR__.'/../fixtures/base/composer.lock',
105+
'target' => __DIR__.'/../fixtures/target/composer.lock',
106+
'--no-dev' => null,
107+
),
108+
),
90109
'no-prod' => array(
91110
<<<OUTPUT
92111
| Dev Packages | Operation | Base | Target |

0 commit comments

Comments
 (0)