From 326a9793028d537bf8575bea1e04d94a67679874 Mon Sep 17 00:00:00 2001 From: Alannah Kearney Date: Tue, 6 Aug 2019 09:02:03 +1000 Subject: [PATCH 1/5] Minor improvement to logic in AbstractInputHandler::validateInput(). Ensures that an input with a validator, but with a default value and no user suplied input, will have the default value used. --- src/Input/AbstractInputHandler.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Input/AbstractInputHandler.php b/src/Input/AbstractInputHandler.php index 97413e0..e0c5e13 100644 --- a/src/Input/AbstractInputHandler.php +++ b/src/Input/AbstractInputHandler.php @@ -68,17 +68,17 @@ abstract class AbstractInputHandler implements Interfaces\InputHandlerInterface if(!Flags\is_flag_set($flags, self::FLAG_VALIDATION_SKIP_REQUIRED)) { self::checkRequiredAndRequiredValue($input, $this->input); } - // There is a default value, input has not been set, and there - // is no validator + // There is a default value and input has not been set. Assign the + // default value to the result. if ( null !== $input->default() && - null === $this->find($input->name()) && - null === $input->validator() + null === $this->find($input->name()) ) { $result = $input->default(); - // Input has been set and it has a validator. Skip this if - // FLAG_VALIDATION_SKIP_CUSTOM is set + // Input has been set AND it has a validator. Run the validator over the + // input. Note, this will be skipped if FLAG_VALIDATION_SKIP_CUSTOM is + // set } elseif (null !== $this->find($input->name()) && null !== $input->validator() && !Flags\is_flag_set($flags, self::FLAG_VALIDATION_SKIP_CUSTOM)) { $validator = $input->validator(); @@ -94,7 +94,8 @@ abstract class AbstractInputHandler implements Interfaces\InputHandlerInterface throw new Exceptions\InputValidationFailedException($input, 0, $ex); } - // No default, no validator, but may or may not have been set + // No default, but may or may not have been set so assign whatever value + // it might have to the result } else { $result = $this->find($input->name()); } From 1e903ea6e1ec01b9f6e1e2763cab730af7b5273c Mon Sep 17 00:00:00 2001 From: Alannah Kearney Date: Tue, 6 Aug 2019 09:03:28 +1000 Subject: [PATCH 2/5] Updated README and CHANGELOG for 1.2.2 release --- CHANGELOG.md | 5 +++++ README.md | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f8a058..dc1ac0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [1.2.2][] +#### Changed +- Minor improvement to logic in `AbstractInputHandler::validateInput()`. Ensures that an input with a validator, but with a default value and no user suplied input, will have the default value used. + ## [1.2.1][] #### Changed - Updated `InputHandlerFactory` and `InputTypeFactory` to work with changes in `pointybeard/helpers-foundation-factory` 1.0.2 @@ -77,6 +81,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). #### Added - Initial release +[1.2.2]: https://github.com/pointybeard/helpers-functions-cli/compare/1.2.1...1.2.2 [1.2.1]: https://github.com/pointybeard/helpers-functions-cli/compare/1.2.0...1.2.1 [1.2.0]: https://github.com/pointybeard/helpers-functions-cli/compare/1.1.4...1.2.0 [1.1.4]: https://github.com/pointybeard/helpers-functions-cli/compare/1.1.3...1.1.4 diff --git a/README.md b/README.md index b4a1f90..be26831 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PHP Helpers: Command-line Input and Input Type Handlers -- Version: v1.2.1 -- Date: June 04 2019 +- Version: v1.2.2 +- Date: Aug 06 2019 - [Release notes](https://github.com/pointybeard/helpers-cli-input/blob/master/CHANGELOG.md) - [GitHub repository](https://github.com/pointybeard/helpers-cli-input) From 2d87f04dffa793e32839d32ef0cb153a506671b2 Mon Sep 17 00:00:00 2001 From: Alannah Kearney Date: Tue, 6 Aug 2019 09:23:59 +1000 Subject: [PATCH 3/5] Removed version information from composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 7191478..eddd6ad 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,5 @@ { "name": "pointybeard/helpers-cli-input", - "version": "1.2.1", "description": "Collection of classes for handling argv (and other) input when calling command-line scripts. Helps with parsing, collecting and validating arguments, options, and flags.", "homepage": "https://github.com/pointybeard/helpers-cli-input", "license": "MIT", From 9622c9825868cf4ad429ed7cd531175c02bdff94 Mon Sep 17 00:00:00 2001 From: Alannah Kearney Date: Thu, 28 Nov 2019 03:33:52 +0000 Subject: [PATCH 4/5] Removed dev packages from composer.json to avoid circular package dependency version issues and removed example for manpage() method. --- composer.json | 5 ----- example/example.php | 29 ----------------------------- 2 files changed, 34 deletions(-) diff --git a/composer.json b/composer.json index eddd6ad..8eea99b 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,6 @@ "pointybeard/helpers-foundation-factory": "~1.0", "pointybeard/helpers-functions-flags": "~1.0" }, - "require-dev": { - "pointybeard/helpers-functions-strings": "~1.1.0", - "pointybeard/helpers-cli-colour": "~1.0", - "pointybeard/helpers-functions-cli": "~1.1.0" - }, "support": { "issues": "https://github.com/pointybeard/helpers-cli-input/issues", "wiki": "https://github.com/pointybeard/helpers-cli-input/wiki" diff --git a/example/example.php b/example/example.php index 76b67e5..1695bf1 100644 --- a/example/example.php +++ b/example/example.php @@ -4,7 +4,6 @@ declare(strict_types=1); include __DIR__.'/../vendor/autoload.php'; use pointybeard\Helpers\Cli\Input; -use pointybeard\Helpers\Cli\Colour\Colour; use pointybeard\Helpers\Functions\Cli; // Define what we are expecting to get from the command line @@ -64,34 +63,6 @@ try { exit; } -// Display the manual in green text -echo Cli\manpage( - basename(__FILE__), - '1.0.2', - 'An example script for the PHP Helpers: Command-line Input and Input Type Handlers composer library (pointybeard/helpers-cli-input).', - $collection, - Colour::FG_GREEN, - Colour::FG_WHITE, - [ - 'Examples' => 'php -f example/example.php -- -vvv -d example/example.json import', - ] -).PHP_EOL.PHP_EOL; - -// example.php 1.0.2, An example script for the PHP Helpers: Command-line Input -// and Input Type Handlers composer library (pointybeard/helpers-cli-input). -// Usage: example.php [OPTIONS]... ACTION... -// -// Arguments: -// ACTION The name of the action to perform -// -// Options: -// -v verbosity level. -v (errors only), -vv -// (warnings and errors), -vvv (everything). -// -d, --data=VALUE Path to the input JSON data -// -// Examples: -// php -f example/example.php -- -vvv -d example/example.json import - var_dump($argv->find('action')); // string(6) "import" From c6fe64321ef06633c89bc055252f22d6ff676d52 Mon Sep 17 00:00:00 2001 From: Norbert Wagner <5166607+n3w@users.noreply.github.com> Date: Thu, 23 Mar 2023 08:47:59 +0100 Subject: [PATCH 5/5] Passing the separator after the array is no longer supported --- src/Input/Types/Argument.php | 2 +- src/Input/Types/LongOption.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Input/Types/Argument.php b/src/Input/Types/Argument.php index 52faec1..4550781 100644 --- a/src/Input/Types/Argument.php +++ b/src/Input/Types/Argument.php @@ -72,6 +72,6 @@ class Argument extends Input\AbstractInputType $second[$ii] = $secondaryLineLeadPadding.$second[$ii]; } - return $first.implode($second, PHP_EOL); + return $first.implode(PHP_EOL, $second); } } diff --git a/src/Input/Types/LongOption.php b/src/Input/Types/LongOption.php index 5961768..17d73de 100644 --- a/src/Input/Types/LongOption.php +++ b/src/Input/Types/LongOption.php @@ -84,6 +84,6 @@ class LongOption extends Input\AbstractInputType $second[$ii] = $secondaryLineLeadPadding.$second[$ii]; } - return $first.implode($second, PHP_EOL); + return $first.implode(PHP_EOL, $second); } }