The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Changes for version 0.055001 - 2022-02-12

  • Enhancements
    • Context-sensitive Completion / Validation `complete` methods now receive a second argument: a HashRef with "state" information that includes the preceding words on the command line (in the `$state->{processed}` ArrayRef) and a collection of options seen so far (in the `$state->{options}` HashRef).
      • Argument validators also receive a "state" parameter HashRef (although it has a different different structure than that of `complete`, see documentation).
      • See the demo script in `examples/context_sensitive_completion/`.
    • Dynamic Enum Arguments The `value_list` of Term::CLI::Argument::Enum objects now accepts a CodeRef, which will be called when the list of values needs to be fetched.
      • The new `values` method returns the actual list of values.
      • The `cache_values` boolean attribute can be used to to execute the list expansion only once.
      • The tutorial has been updated to include this.
    • Dynamic Command Lists The `commands` argument of Term::CLI and Term::CLI::Commands objects (through Term::CLI::Role::CommandSet) now accepts a CodeRef, which will only be called the first time the command list is needed. This allows for delayed command building, which, if used in deeper levels of a command hierarchy, can reduce start-up time.
      • A new `delete_command` method allows for dynamic command hierarchies [RFE#16]. See `examples/dynamic_commands.pl` for a demo of this.
    • New `state` attribute for Term::CLI and Term::CLI::Command These classes now use a new role called Term::CLI::Role::State that provides a "state" HashRef that can be used to store application-specific state.
    • Term::CLI Create a ReadLine object that uses `STDIN` and `STDOUT` by default, instead of letting (Gnu) ReadLine find and open the TTY separately. This ensures that:
      • perl readline_app < input_file
      • will actually read input from `input_file`, while also making sure that whatever encoding you have on the standard I/O handles (e.g. `use open qw(:std :utf8)`) will also be applied to ReadLine's I/O. This means that Estonians can write "tõsi" for "true" and Macedonians can write "лажни" for "false".
    • Term::CLI::Argument::Boolean Completions now match the case of the partial text, so "TR" gets completed to "TRUE" instead of "TRue".
    • Term::CLI::Role::CommandSet Command lists are now always sorted by name internally. This allows for optimised searching/matching.
    • Term::CLI::Argument::Enum Value lists are always sorted internally. This allows for optimised searching/matching, see also examples/big_enum.pl
  • New
    • Term::CLI::Util New module with a few utility functions for other modules.
    • Term::CLI::Role::State A `Moo::Role` that adds a `state` hash to objects. See examples/state_demo.pl.
    • benchmarks/* A few scripts with benchmarks for different approaches to particular algorithms.
    • examples/cli_context.pl Demo script for CLI context (provided by djerius).
  • Tests
    • Various updates and fixes to test the new functionalities.
  • Bug Fixes
    • Term::CLI::Argument::Bool
      • Fix case-sensitive completion (used `lc` where we shouldn't).
      • Fix test cases for case-insenstive (enum) completion.
    • tutorial/example_17_suspend.pl Don't suspend if there was an error on the command line input.
    • Fix Boolean bug in tutorial (and accompanying code). We specified "1" as a valid value for "false"; that should be "0".
  • Miscellaneous
    • Eliminate unnecessary `shift` of function argument in favour of assigning from `@_`.
    • Improve Dutch translation of "unknown (sub-)command"
    • Fix dependency on Test::MockModule so it builds on FreeBSD 12.
    • POD fixes and updates.
    • Term::CLI::Command Modify error message for invalid arguments for readability.

Documentation

introduction to Term::CLI class/module structure
tips, tricks, and examples for Term::CLI

Modules

CLI interpreter based on Term::ReadLine
generic parent class for arguments in Term::CLI
class for "boolean" arguments in Term::CLI
class for "enum" string arguments in Term::CLI
class for file name arguments in Term::CLI
base class for numerical arguments in Term::CLI
class for floating point arguments in Term::CLI
class for integer arguments in Term::CLI
class for basic string arguments in Term::CLI
generic base class for Term::CLI classes
Class for (sub-)commands in Term::CLI
A generic 'help' command for Term::CLI
generic parent class for elements in Term::CLI
localizations for Term::CLI
English localizations for Term::CLI
Dutch localizations for Term::CLI
Term::ReadLine compatibility layer for Term::CLI
Manage command arguments in Term::CLI
Role for (sub-)commands in Term::CLI
Role for generating help text in Term::CLI
Keep a "state" hash in Term::CLI objects
utility functions for Term::CLI(3p)