From f09cf8eb1d8fa446b862661fef9e747ab91a6c5b Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Mon, 11 Apr 2016 11:39:21 +0200 Subject: [PATCH 1/3] Support for user defined comments per file Closes #99 --- Processor.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Processor.php b/Processor.php index 6dc208f..8e8c0bd 100644 --- a/Processor.php +++ b/Processor.php @@ -104,7 +104,7 @@ private function processParams(array $config, array $expectedParams, array $actu // Add the params coming from the environment values $actualParams = array_replace($actualParams, $this->getEnvValues($envMap)); - return $this->getParams($expectedParams, $actualParams); + return $this->getParams($expectedParams, $actualParams, $config); } private function getEnvValues(array $envMap) @@ -137,7 +137,7 @@ private function processRenamedValues(array $renameMap, array $actualParams) return $actualParams; } - private function getParams(array $expectedParams, array $actualParams) + private function getParams(array $expectedParams, array $actualParams, array $config = []) { // Simply use the expectedParams value as default for the missing params. if (!$this->io->isInteractive()) { @@ -153,7 +153,11 @@ private function getParams(array $expectedParams, array $actualParams) if (!$isStarted) { $isStarted = true; - $this->io->write('Some parameters are missing. Please provide them.'); + if (empty($config['comment'])) { + $this->io->write('Some parameters are missing. Please provide them.'); + } else { + $this->io->write('' . $config['comment'] . ''); + } } $default = Inline::dump($message); From f1118d1b81eeb2bf9730aed0dfd6adc80975b8e4 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Mon, 11 Apr 2016 11:43:45 +0200 Subject: [PATCH 2/3] fix for PHP 5.3 --- Processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Processor.php b/Processor.php index 8e8c0bd..a291cd5 100644 --- a/Processor.php +++ b/Processor.php @@ -137,7 +137,7 @@ private function processRenamedValues(array $renameMap, array $actualParams) return $actualParams; } - private function getParams(array $expectedParams, array $actualParams, array $config = []) + private function getParams(array $expectedParams, array $actualParams, array $config = array()) { // Simply use the expectedParams value as default for the missing params. if (!$this->io->isInteractive()) { From e5a5588bfb75e84c765476ee8bfc7696f9161526 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Tue, 12 Apr 2016 15:20:15 +0200 Subject: [PATCH 3/3] add tests for comment option use sprintf for writing comment --- Processor.php | 2 +- Tests/ProcessorTest.php | 6 +++++- .../interaction_existent_with_comment/dist.yml | 4 ++++ .../existing.yml | 3 +++ .../expected.yml | 5 +++++ .../interaction_existent_with_comment/setup.yml | 14 ++++++++++++++ .../dist.yml | 4 ++++ .../expected.yml | 10 ++++++++++ .../setup.yml | 17 +++++++++++++++++ 9 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 Tests/fixtures/testcases/interaction_existent_with_comment/dist.yml create mode 100644 Tests/fixtures/testcases/interaction_existent_with_comment/existing.yml create mode 100644 Tests/fixtures/testcases/interaction_existent_with_comment/expected.yml create mode 100644 Tests/fixtures/testcases/interaction_existent_with_comment/setup.yml create mode 100644 Tests/fixtures/testcases/interaction_non_existent_with_comment/dist.yml create mode 100644 Tests/fixtures/testcases/interaction_non_existent_with_comment/expected.yml create mode 100644 Tests/fixtures/testcases/interaction_non_existent_with_comment/setup.yml diff --git a/Processor.php b/Processor.php index a291cd5..7e5c054 100644 --- a/Processor.php +++ b/Processor.php @@ -156,7 +156,7 @@ private function getParams(array $expectedParams, array $actualParams, array $co if (empty($config['comment'])) { $this->io->write('Some parameters are missing. Please provide them.'); } else { - $this->io->write('' . $config['comment'] . ''); + $this->io->write(sprintf('%s', $config['comment'])); } } diff --git a/Tests/ProcessorTest.php b/Tests/ProcessorTest.php index babf44a..f3b36a7 100644 --- a/Tests/ProcessorTest.php +++ b/Tests/ProcessorTest.php @@ -151,7 +151,11 @@ private function setInteractionExpectations(array $testCase) } if (!empty($testCase['requested_params'])) { - $this->io->write('Some parameters are missing. Please provide them.')->shouldBeCalledTimes(1); + if (empty($testCase['config']['comment'])) { + $this->io->write('Some parameters are missing. Please provide them.')->shouldBeCalledTimes(1); + } else { + $this->io->write(sprintf('%s', $testCase['config']['comment']))->shouldBeCalledTimes(1); + } } foreach ($testCase['requested_params'] as $param => $settings) { diff --git a/Tests/fixtures/testcases/interaction_existent_with_comment/dist.yml b/Tests/fixtures/testcases/interaction_existent_with_comment/dist.yml new file mode 100644 index 0000000..4134d19 --- /dev/null +++ b/Tests/fixtures/testcases/interaction_existent_with_comment/dist.yml @@ -0,0 +1,4 @@ +parameters: + foo: bar + boolean: false + another: ~ diff --git a/Tests/fixtures/testcases/interaction_existent_with_comment/existing.yml b/Tests/fixtures/testcases/interaction_existent_with_comment/existing.yml new file mode 100644 index 0000000..c31530c --- /dev/null +++ b/Tests/fixtures/testcases/interaction_existent_with_comment/existing.yml @@ -0,0 +1,3 @@ +# This file is auto-generated during the composer install +parameters: + foo: existing_foo diff --git a/Tests/fixtures/testcases/interaction_existent_with_comment/expected.yml b/Tests/fixtures/testcases/interaction_existent_with_comment/expected.yml new file mode 100644 index 0000000..73f278e --- /dev/null +++ b/Tests/fixtures/testcases/interaction_existent_with_comment/expected.yml @@ -0,0 +1,5 @@ +# This file is auto-generated during the composer install +parameters: + foo: existing_foo + boolean: false + another: 'null' diff --git a/Tests/fixtures/testcases/interaction_existent_with_comment/setup.yml b/Tests/fixtures/testcases/interaction_existent_with_comment/setup.yml new file mode 100644 index 0000000..3884911 --- /dev/null +++ b/Tests/fixtures/testcases/interaction_existent_with_comment/setup.yml @@ -0,0 +1,14 @@ +title: Existing values are not asked interactively again + +interactive: true + +config: + comment: 'Please provide your configuration parameters' + +requested_params: + boolean: + default: 'false' + input: 'false' + another: + default: 'null' + input: '"null"' diff --git a/Tests/fixtures/testcases/interaction_non_existent_with_comment/dist.yml b/Tests/fixtures/testcases/interaction_non_existent_with_comment/dist.yml new file mode 100644 index 0000000..c6e5b2c --- /dev/null +++ b/Tests/fixtures/testcases/interaction_non_existent_with_comment/dist.yml @@ -0,0 +1,4 @@ +parameters: + boolean: false + another: test + nested: nested diff --git a/Tests/fixtures/testcases/interaction_non_existent_with_comment/expected.yml b/Tests/fixtures/testcases/interaction_non_existent_with_comment/expected.yml new file mode 100644 index 0000000..84b8ddd --- /dev/null +++ b/Tests/fixtures/testcases/interaction_non_existent_with_comment/expected.yml @@ -0,0 +1,10 @@ +# This file is auto-generated during the composer install +parameters: + boolean: true + another: null + nested: + foo: bar + bar: + - foo + - test + - null diff --git a/Tests/fixtures/testcases/interaction_non_existent_with_comment/setup.yml b/Tests/fixtures/testcases/interaction_non_existent_with_comment/setup.yml new file mode 100644 index 0000000..28b0ac0 --- /dev/null +++ b/Tests/fixtures/testcases/interaction_non_existent_with_comment/setup.yml @@ -0,0 +1,17 @@ +title: Missing keys are asked interactively + +interactive: true + +config: + comment: 'Please provide your configuration parameters' + +requested_params: + boolean: + default: 'false' + input: 'true' + nested: + default: nested + input: '{foo: bar, bar: [foo, test, null]}' + another: + default: test + input: 'null'