CliToolkit -> Changelog
This change log references the repository changes and releases, which respect semantic versioning.
- Adapted the codebase to work smoothly with PHP 8.5
- Updated PHPUnit: 12.1.0 -> 12.5.6
- Added short descriptions to all EnvironmentConfig.php settings.
- Improved docs a bit.
-
Fixed a possible bug when a parent config parameter value is replaced with a subcommand parameters' values in a request multi-dimensional array. Example: when adding
listparameter to a main config, it's value was then replaced withlistsubcommand sub-request values.The fix became possible with adding a special prefix to a request array key connected to a subcommand request values sub-array. Such a prefix can not be added to a parameter or subcommand name without a configuration error, which makes such request key naming safe.
If previously you could access
magicsubcommand request parameters from the main request by$request->getParams()['magic'], from now on you should be OK with the built-in handy method$request->getSubcommandRequest(), which does not require specifying a chosen subcommand name - it detects that name automatically.However, if you want to check for existence of a particular request (subcommand call) manually, from now on you should do it this way:
$request->getParams()[CliRequest::SUBCOMMAND_PREFIX . 'magic'](wheremagicis a subcommand name).- Added
CliRequest::SUBCOMMAND_PREFIXfor subcommand request key names.
- Added
-
cli-toolkit plain scripts are removed to be replaced with ScriptClassAbstract.php-based scripts and a launcher, run.php.
- CompletionScript.php now utilizes ScriptFileDetector.php, thus the search-related parameters were changed accordingly.
-
HelpGenerator::getSubcommandsBlock()is removed - replaced withlistbuilt-in subcommand. -
CliRequest::getSubcommandRequest(): removed$subcommandNameparameter, changed return type hint fromstringto?string: now the method always returns the called subcommand's request object ornullif there was no subcommand call. -
CliRequestProcessor::$configbecame readonly - you can not edit it after passing to__construct(). -
__construct()method became protected. Nowcreate()static method is the only way to create an instance.QUESTION_POSTFIXconstant is removed. Now the default value is set directly for$questionPostfixproperty.getInput()trims the input instead ofgetAnswerOrDefault()that utilizes the former.- If
possibleAnswers()are set withoutisCaseSensitivemode enabled, the answer returned byask()method will contain one of original possible answers: ifYESis expected as one of answers and you provideyes,ask()will returnYESas your answer (notyes, as was done in a previous version).
-
- Moved to its own subdirectory, updated the namespace.
- Removed
getSubcommandsBlock()(so as "COMMANDS" block output fromgetFullHelp()) to replace it withlistbuilt-in subcommand functionality. - Removed
getBaseScriptName()obsolete method. - Changed visibility from
publictoprotectedfor methodsgetDescriptionBlock()andgetUsagesBlock(). - Added the third, mandatory
HelpFormatterparameter togetUsageForParseErrorException(). getParamsBlock():- Made non-static.
- Removed
$formatterparameter. - Changed visibility from
publictoprotected.
makeDefinitionList():- Made non-static.
- Removed
$formatter, the first parameter. - The last parameter,
string $titleis changed into an array ofHelpParameterDefinition. - Padding improvement: option full names are padded to start at the same column, if there is at least one short name present.
- Made
makeParamDescriptionnon-static, removed$formatterparameter. - Moved constants to
EnvironmentConfigas its properties to ease changing of the corresponding settings:-
PAD_LEFT_MAIN->helpGeneratorPaddingLeftMain -
PAD_LEFT_PARAM_DESCRIPTION->helpGeneratorPaddingLeftParameterDescriptionThe value is changed from
3to4. -
USAGE_MAX_OPTIONS->helpGeneratorUsageNonRequiredOptionsMax
-
-
TerminalFormatter::__construct()expectsbool $isDisabledinstead ofint|resource $resource: now it is possible to instantiate a formatter object that applies (or not) formatting with guarantee.createForStdOut()andcreateForStdErr()work as usual (stream_isatty()call is moved in those methods). -
Removed
EnvironmentConfig::detectTopmostDirectoryPath()method - replaced its usage withUtils::detectTopmostProjectRootDirectory() -
Renaming:
Config::newSubcommand()first parameter$subcommandValue->$subcommandName.BuilderInterface::newSubcommand()(so asBuilderAbstractandConfigBuilder) first parameter$subcommandValue->$subcommandName.- Completion.php:
executeAutocomplete()->executeCompletiongenerateAutocompleteScript()->generateCompletionCode()
- Config.php:
OPTION_NAME_HELP->PARAMETER_NAME_HELPOPTION_NAME_AUTOCOMPLETE_GENERATE->PARAMETER_NAME_COMPLETION_GENERATE(its valueparametizer-internal-autocomplete-generate->parametizer-internal-completion-generate)OPTION_NAME_AUTOCOMPLETE_EXECUTE->PARAMETER_NAME_COMPLETION_EXECUTE(its valueparametizer-internal-autocomplete-execute->parametizer-internal-completion-execute)
-
composer.json: the
typeis changed fromprojecttolibrary. Not sure if it should be treated as incompatibility, but let's note it here just in case.
-
Removed "minimum 2 subcommands" constraint from
Config::commitSubcommandSwitch(). -
ScriptClassAbstract.php as a basement for class-based Parametizer-powered scripts.
EnvironmentConfig::detectBottommostDirectoryPath()now tries to detect the class' "child" location when possible. Otherwise backwards to a launched script location.
-
Subcommand names (
Config::newSubcommand()) now support the colon (:) symbol. Main purpose - a separator for script classes sections. -
Built-in subcommands: each script with a subcommand switch automatically provides you with
help(ShowHelpPage.php) andlist(ListSubcommands.php) built-in subcommands.- Every subcommand switch goes with
listas its default value. - All built-in subcommands always utilize a parent EnvironmentConfig.php instance (from a parent Config.php).
- Every subcommand switch goes with
-
ScriptFileDetector.php detects plain
Parametizer-based scripts. The result is mainly used to compile a completion script by CompletionScript.php -
ScriptClassDetector.php detects ScriptClassAbstract.php-based scripts. The result is mainly used as subcommands for ScriptClassLauncher.php (see below).
-
ScriptClassLauncher.php enables a ready-to-go mean to load and launch ScriptClassAbstract.php-based scripts.
The launcher class includes ClearCache.php subcommand that is automatically added to a launcher's config, if a launcher's script detector enables caching and a cache file exists. The subcommand lets you delete the created cache file.
-
Added
ConfigBuilder::shortDescription()- such manually set descriptions are not affected by the description shortener. Useful when environment settings are not optimal for all descriptions. -
- Added an optional
$areHiddenForHelpparameter forallowedValues()method, defaults tofalse. - Added a protected method
setAllowedValues()for common internal operations with the allowed values list.
- Added an optional
-
ParameterAbstract.php: added a protected property
$areAllowedValuesHiddenFromHelp, a related getter methodareAllowedValuesHiddenFromHelp(), and a related optional parameter$areHiddenFromHelpforallowedValues()method. -
- Modified
makeParamDescription():- Utilizes
$areAllowedValuesHiddenFromHelpparameter property and does not show the list of values if the flag is set totrue. - For subcommands: replaces "Allowed values" actual list with a hint about detected subcommands count and a subcommand name to show all available subcommands.
- Utilizes
- Added
getScriptShortDescription()that returns a manual short description set in a config or a shortened full description (based on specifiedEnvironmentConfigobject). - Added the second,
HelpFormatterparameter to__construct().
- Modified
-
Added new setting for EnvironmentConfig.php:
-
__construct()changes:$configparameter is made public (from protected).- Added
$parentparameter to access parent request (from a subcommand request).
- Added
getRequestedSubcommandName()method. - Added
executeBuiltInSubcommandIfRequested()method for built-in subcommands automatic execution; the method is utilized byParametizer::run().
-
Added
CliRequestProcessor::parseSubcommandParameters()protected method to ease processing of the default subcommand name (subcommand switch value). -
Added
CliRequestProcessor::$isForCompletionreadonly flag (settable in__construct()). The flag is used to stabilize completion output due to the default subcommand switch value. -
- Added public
getBuiltInSubcommandClassesBySubcommandNames()method and the related methods:- public
getSubcommandSwitchName()- to get a subcommand switch parameter name if present in a config; - public
getBuiltInSubcommandClass()- to get a subcommand fully qualified class name by a subcommand name; - public
getBuiltInSubcommands()- to get the list of built-in subcommand configs by their names; - protected
addBuiltInSubcommands()- an internal method to add built-in subcommands automatically to every script that contains a subcommand switch parameter.
- public
- Added
getArgumentsByNames()that has argument names as keys, whilegetArguments()still renders numeric keys. - Added
$shortDescriptionprotected property, the settershortDescriptionand the gettergetShortDescription.
- Added public
-
CliToolkitScriptAbstract.php as a basement for all tools/cli-toolkit scripts.
-
Formatters:
- Added
HelpFormatter::invert(). - Added
ScriptFormatter::note().
- Added
-
- Added
askAway()static method to shorten code in case there is no need for answer validation or any other setup. - Added
$dieMessageparameter toQuestion::confirmOrDie()method - outputs a message (if provided) before interrupting script's execution.
- Added
-
Utils.php for various stuff used in different places and structurally not fitting into any other class.
-
GenerateMassTestScripts.php as a tool to test the performance and other "law of large numbers" cases, when a launcher includes lots of class scripts.
- Question.php:
-
validateAnswer()addserrorMessageonly if it was filled inpossibleAnswers().Also, the dot symbol is removed. So now it is possible to decide yourself if any stop symbol is needed. For instance, you may want to see something like this:
Oops :( Possible answers: ..., so there is no dot after:(. -
Changed
possibleAnswers()andanswerValidatorPattern()defaulterrorMessagetoInvalid answer.(added a dot symbol) - because of the change mentioned above. -
Improved a bit exception messages when both a list of possible answers and a validation pattern are set.
-
VariableBuilderAbstract::ensureNotRequiredAndHasDefaultSimultaneously(): fixed a bit the exception message.HelpGenerator::getParamsBlock(), options block sort improvement: as previously, options are grouped byisRequired()state (required options go first), but from now on each group is additionally sorted by names.
-
AutoloadDetector.php is added for init.php.
Previously all built-in scripts (cli-toolkit) could not be launched without calling
composer installadditionally inside the library directory. And from now on your main project'svendor/autoload.phppath should be detectable.
-
PHPUnit version is upgraded from
^10to12.1.0.From now on PHPUnit engine itself is not present in the library and should be installed and launched separately.
-
Test classes are auto-loaded only during actual test launches. E.g. if you accidentally use
tests/utils/CliProcessin your production classes under 'dev' environment (when you callcomposer installwithout--no-devoption), you will get "Class 'XXX' not found in ..." error. Previously there was no error, until you install composer packages with--no-devflag. -
- Fixed scripts main description block - stopped counting symbols in space-only lines. Previously it caused too much padding for descriptions with too short space-only lines.
- Improved subcommand help usage block - when
--helpis called for a subcommand, all manual usage lines include the whole path (subcommand names) starting from the topmost config.
- PHP minimal required version is 8.3.
- Set explicitly types for all classes constants.
Config::createHelpOption()is deleted because not needed anymore (see the point below).Parametizer::setExceptionHandlerForParsing()requires aCliRequestProcessorobject,HelpGenerator::getUsageForParseErrorException()requires aConfigobject as the second parameter,CliRequestProcessor::__construct()is added with a requiredConfigobject parameter,CliRequestProcessor::load()signature is changed -Configobject parameter is removed. This way it's possible to get an innermost branch config forParseErrorExceptioninstances.$isForStdErrparameter is removed fromHelpGenerator::getUsageForParseErrorException(), the method always use a formatter for STDERR stream.Parametizer::setExceptionHandlerForParsing()renders both an error message and a help block in STDERR (previously a help block was rendered in STDOUT).Option::getOptionCleanFullName()is deleted because of no usage.- Renaming:
CliRequest::getCommandRequest()->getSubcommandRequest()CliRequestProcessor::getAllowedArguments()->getInnermostBranchAllowedArguments()CliRequestProcessor::append()->appendToInnermostBranch()
HelpGenerator::getUsageTemplate()is made protected (from public) and non-static. Then it's able to use an instance$formatterproperty (instead of creating a separate formatter instance).
- Added Environment Config that allows setting "environment"-related
options like a short name for built-in
--helpoption and short description boundaries. Other changes provoked by this addition:Config::__construct(),ConfigBuilder::__construct()andParametizer::newConfig()support a new optional parameter$envConfigto passEnvironmentConfiginstance.- Added
Config::$envConfigprotected property to keepEnvironmentConfiginstance and the relatedgetEnvConfig()public method.
CliRequestprovidesgetParamAs*helper methods for easier parameters' values type casting, see Features Manual: Type casting from requests.- Added
HelpGenerator::getShortDescription()that is used to show short versions for subcommand descriptions, when outputting a help page for a script with a list of available subcommands.
- Added a paragraph about subcommands into Features Manual: Subcommands.
- Formatted subcommand name in
HelpGenerator::getUsageTemplate(), so subcommands would be more visible in the 'COMMANDS' section of a help page with a list of available subcommands. - Fixed completion for option short names in subcommands.
- Made completion smarter: duplicate option and value mentioning is not completed.
The first official release. Mainly focused on Cliff improvements and some additions like:
- more transparent and convenient config builder;
- generate-autocompletion-scripts.php (eases completion init);
- TerminalFormatter (helps format the improved generated help pages);
- Question (helps implement interactive scripts);
- PHPUnit for autotests plus more autotests.