diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f83964b..0b46e262 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,9 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
-For a full diff see [`2.1.2...master`][2.1.2...master].
+For a full diff see [`2.2.0...master`][2.2.0...master].
-## [`2.1.2`][2.1.1]
+## [`2.2.0`][2.2.0]
+
+For a full diff see [`2.1.2...2.2.0`][2.1.2...2.2.0].
+
+### Added
+
+* Added `--diff` option ([#303]), by [@localheinz]
+
+## [`2.1.2`][2.1.2]
For a full diff see [`2.1.1...2.1.2`][2.1.1...2.1.2].
@@ -284,6 +292,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
[2.1.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.1.0
[2.1.1]: https://github.com/ergebnis/composer-normalize/releases/tag/2.1.1
[2.1.2]: https://github.com/ergebnis/composer-normalize/releases/tag/2.1.2
+[2.2.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.2.0
[81bc3a8...0.1.0]: https://github.com/ergebnis/composer-normalize/compare/81bc3a8...0.1.0
[0.1.0...0.2.0]: https://github.com/ergebnis/composer-normalize/compare/0.1.0...0.2.0
@@ -309,7 +318,8 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
[2.0.2...2.1.0]: https://github.com/ergebnis/composer-normalize/compare/2.0.2...2.1.0
[2.1.0...2.1.1]: https://github.com/ergebnis/composer-normalize/compare/2.1.0...2.1.1
[2.1.1...2.1.2]: https://github.com/ergebnis/composer-normalize/compare/2.1.1...2.1.2
-[2.1.2...master]: https://github.com/ergebnis/composer-normalize/compare/2.1.2...master
+[2.1.2...2.2.0]: https://github.com/ergebnis/composer-normalize/compare/2.1.2...2.2.0
+[2.2.0...master]: https://github.com/ergebnis/composer-normalize/compare/2.2.0...master
[#1]: https://github.com/ergebnis/composer-normalize/pull/1
[#2]: https://github.com/ergebnis/composer-normalize/pull/2
@@ -349,6 +359,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
[#292]: https://github.com/ergebnis/composer-normalize/pull/292
[#297]: https://github.com/ergebnis/composer-normalize/pull/297
[#301]: https://github.com/ergebnis/composer-normalize/pull/301
+[#303]: https://github.com/ergebnis/composer-normalize/pull/303
[@ergebnis]: https://github.com/ergebnis
[@localheinz]: https://github.com/localheinz
diff --git a/README.md b/README.md
index ddb8afdc..5aa592a6 100644
--- a/README.md
+++ b/README.md
@@ -119,6 +119,7 @@ The `NormalizeCommand` provided by the `NormalizePlugin` within this package wil
### Options
+* `--diff`: Show the results of normalizing
* `--dry-run`: Show the results of normalizing, but do not modify any files
* `--indent-size`: Indent size (an integer greater than 0); should be used with the `--indent-style` option
* `--indent-style`: Indent style (one of "space", "tab"); should be used with the `--indent-size` option
diff --git a/src/Command/NormalizeCommand.php b/src/Command/NormalizeCommand.php
index ffa865cf..7d89413c 100644
--- a/src/Command/NormalizeCommand.php
+++ b/src/Command/NormalizeCommand.php
@@ -64,6 +64,12 @@ protected function configure(): void
Console\Input\InputArgument::OPTIONAL,
'Path to composer.json file'
),
+ new Console\Input\InputOption(
+ 'diff',
+ null,
+ Console\Input\InputOption::VALUE_NONE,
+ 'Show the results of normalizing'
+ ),
new Console\Input\InputOption(
'dry-run',
null,
@@ -192,7 +198,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
return 0;
}
- if (true === $input->getOption('dry-run')) {
+ if (true === $input->getOption('diff') || true === $input->getOption('dry-run')) {
$io->writeError(\sprintf(
'%s is not normalized.',
$composerFile
@@ -212,7 +218,9 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
'----------- end diff ----------->',
'',
]);
+ }
+ if (true === $input->getOption('dry-run')) {
return 1;
}
diff --git a/test/Integration/Command/NormalizeCommandTest.php b/test/Integration/Command/NormalizeCommandTest.php
index ce47ea2f..5e40c67d 100644
--- a/test/Integration/Command/NormalizeCommandTest.php
+++ b/test/Integration/Command/NormalizeCommandTest.php
@@ -392,6 +392,57 @@ public function testSucceedsWhenComposerJsonIsPresentAndValidAndComposerLockIsNo
self::assertComposerLockFileNotExists($currentState);
}
+ /**
+ * @dataProvider providerCommandInvocation
+ *
+ * @param CommandInvocation $commandInvocation
+ */
+ public function testSucceedsWhenComposerJsonIsPresentAndValidAndComposerLockIsNotPresentAndComposerJsonIsNotYetNormalizedAndDiffOptionIsUsed(CommandInvocation $commandInvocation): void
+ {
+ $scenario = self::createScenario(
+ $commandInvocation,
+ __DIR__ . '/../../Fixture/json/valid/lock/not-present/json/not-yet-normalized'
+ );
+
+ $initialState = $scenario->initialState();
+
+ self::assertComposerJsonFileExists($initialState);
+ self::assertComposerLockFileNotExists($initialState);
+
+ $application = self::createApplicationWithNormalizeCommandAsProvidedByNormalizePlugin();
+
+ $input = new Console\Input\ArrayInput($scenario->consoleParametersWith([
+ '--diff' => true,
+ ]));
+
+ $output = new Console\Output\BufferedOutput();
+
+ $exitCode = $application->run(
+ $input,
+ $output
+ );
+
+ self::assertExitCodeSame(0, $exitCode);
+
+ $expected = \sprintf(
+ 'Successfully normalized %s.',
+ $scenario->composerJsonFileReference()
+ );
+
+ $renderedOutput = $output->fetch();
+
+ self::assertStringContainsString($expected, $renderedOutput);
+ self::assertStringContainsString('--- original', $renderedOutput);
+ self::assertStringContainsString('+++ normalized', $renderedOutput);
+ self::assertStringContainsString('---------- begin diff ----------', $renderedOutput);
+ self::assertStringContainsString('----------- end diff -----------', $renderedOutput);
+
+ $currentState = $scenario->currentState();
+
+ self::assertComposerJsonFileModified($initialState, $currentState);
+ self::assertComposerLockFileNotExists($currentState);
+ }
+
/**
* @dataProvider providerCommandInvocation
*