yahvya/php-cli-tool-builder

PHP library which helps to build cli php scripts

dev-master 2025-08-25 20:07 UTC

This package is auto-updated.

Last update: 2025-08-25 20:11:23 UTC


README

A lightweight library to build your own custom CLI scripts.

๐Ÿ“„ Library Details

  • ๐Ÿ‘ค Author and maintainer: Yahaya Bathily - GitHub
  • ๐Ÿ“„ License: MIT
  • ๐Ÿงพ License usage: Free to use in both commercial and non-commercial projects under the MIT license.
  • ๐Ÿ—“๏ธ Created at: 25/08/2025

๐Ÿ“š Documentation

The steps to create your own scripts are as follows:

  • Create your command classes by implementing the CliCommand interface
  • Create the script file
  • Load your autoload file
  • Create an instance of the CliToolBuilder class with the expected configuration like bellow
  • Call the treat input method with the arguments of the script as a parameter (you can simulate your arguments by passing a formated array like $argv, 'command name' 'arguments...')
<?php

use Yahvya\PhpCliToolBuilder\Builder\CliToolBuilder;
use Yahvya\PhpCliToolBuilder\Builder\CliToolConfiguration;
use Yahvya\PhpCliToolBuilder\Default\Command\HelpCommand;

require_once(__DIR__ . "/vendor/autoload.php");

$cliToolBuilder = new CliToolBuilder(
    configuration: new CliToolConfiguration(
        toolName: "cli-lib",
        toolDescription: "A tool to help you build your cli tool",
        toolVersion: "1.0.0",
        toolAuthor: "Yahvya",
        commands: [
            new HelpCommand()
        ]
    )
);

try
{
    $cliToolBuilder->treatInput(cliArguments: $argv);
}
catch(Exception $e)
{
    echo $e->getMessage();
}

There are also some 'traits' available under the Yahvya\PhpCliToolBuilder\Power namespace that you can use to develop your commands quickly.

  • SearchArgumentPower : allows searching arguments in different ways

โœ… Library Test Coverage

To run the tests, clone the repository and run:

php vendor/bin/phpunit

Code Coverage Report



Code Coverage Report:
  2025-08-25 20:06:29

 Summary:
  Classes: 66.67% (2/3)
  Methods: 60.00% (3/5)
  Lines:   59.46% (22/37)

Yahvya\PhpCliToolBuilder\Builder\CliToolBuilder
  Methods:  33.33% ( 1/ 3)   Lines:  53.12% ( 17/ 32)
Yahvya\PhpCliToolBuilder\Builder\CliToolConfiguration
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
Yahvya\PhpCliToolBuilder\Power\SearchArgumentPower
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  4/  4)

๐Ÿ™Œ Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

๐Ÿ“ซ Contact

If you have any questions or suggestions, feel free to reach out via GitHub.