PHP Readline Function with Auto-Complete: Run commands from CLI and auto-complete parameters

Recommend this page to a friend!
  Info   View files Documentation   View files View files (19)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2020-12-28 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 38 All time: 10,065 This week: 342Up
Version License PHP version Categories
php_component_cli_re 1.0.0GNU Lesser Genera...5PHP 5, Unix, Console
Description Author

This package can run commands from CLI and auto-complete parameters.

It takes an array with configuration details about the commands that it can execute when it runs on the command line console and executes then the user finishes entering the command.

The package provides auto-complete support, so it can complete each command with parameters when the users types the first letters of the parameter after the command name.

Innovation Award
PHP Programming Innovation award nominee
December 2020
Number 3
Sometimes it is necessary to execute commands from the console command line to execute maintenance tasks in the server on which a PHP application is running.

Some of those tasks as run by typing the name of commands and their parameters in the console. For us humans it is hard to remember all the names of the commands their parameter names.

This package can help to remember the command parameters by allowing to type the commands and provide auto-complete aid to help remember the right name of the parameters.

Manuel Lemos
Picture of nvb
  Performance   Level  
Name: nvb <contact>
Classes: 17 packages by
Country: Germany Germany
Innovation award
Innovation award
Nominee: 10x

Details

Readline Component for PHP

This project aims to deliver an easy to use and free as in freedom php compontent for dealing with unix console readline and autocomplete php scripts.

The build status of the current master branch is tracked by Travis CI: Build Status Latest stable

The scrutinizer status are: code quality | build status

The versioneye status is: Dependency Status

Take a look on openhub.net.

The current change log can be found here.

Benefits

  • autocomplete support
  • readline support
  • configuration as array * set array with possible autocomplete options * bind actions to specific autocomplete options * supports function, closures and objects as autocomplete target
  • easy up php's readline implementation as seen here
  • works with PHP 5.3 and above

Usage

use Net\Bazzline\Component\Cli\Readline\ManagerFactory;

require_once __DIR__ . '/../vendor/autoload.php';

$factory    = new ManagerFactory();
$manager    = $factory->create();
$myClass    = new MyClass();    //assuming a class "MyClass" exists

$manager->setConfiguration(
    array(
        'git' => array(
            'add' => function ($files) {
                if (!is_null($files)) {
                    passthru('/usr/bin/env git add ' . implode(' ', $files));
                }
            },
            'commit' => function ($message) {
                if (is_null($message)) {
                    passthru('/usr/bin/env git commit');
                } else {
                    passthru('/usr/bin/env git commit -m "' . (string) $message . '"');
                }
            }
        ),
        'info' => 'phpinfo',
        'my' => array(
            'function_one' => array($myClass, 'one'),   //assuming MyClass has a method "one"
            'function_two' => array($myClass, 'two')    //assuming MyClass has a method "two"
        )
    )
);
$manager->setPrompt(': ');
$manager->run();

The example above would result into the following possible autocompletion cases.

  • no word * git * info * my
  • first word is git * add * commit
  • first word is my * function_one * function_two

Install

By Hand

mkdir -p vendor/net_bazzline/php_component_cli_readline
cd vendor/net_bazzline/php_component_cli_readline
git clone https://github.com/bazzline/php_component_cli_readline .

With Packagist

composer require net_bazzline/php_component_cli_readline:dev-master

API

API is available at bazzline.net.

Other Great Components

Final Words

Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it :-D.

  Files folder image Files  
File Role Description
Files folder imageexample (1 file)
Files folder imagesource (5 files, 1 directory)
Files folder imagetest (2 files, 1 directory)
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  example  
File Role Description
  Plain text file basic Class Class source

  Files folder image Files  /  source  
File Role Description
Files folder imageConfiguration (3 files)
  Plain text file Autocomplete.php Class Class source
  Plain text file DebugManager.php Class Class source
  Plain text file Manager.php Class Class source
  Plain text file ManagerFactory.php Class Class source
  Plain text file ReadLine.php Class Class source

  Files folder image Files  /  source  /  Configuration  
File Role Description
  Plain text file Assembler.php Class Class source
  Plain text file Executable.php Class Class source
  Plain text file Validator.php Class Class source

  Files folder image Files  /  test  
File Role Description
Files folder imageConfiguration (1 file)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file TestCase.php Class Class source

  Files folder image Files  /  test  /  Configuration  
File Role Description
  Plain text file ValidatorTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:38
This week:0
All time:10,065
This week:342Up

For more information send a message to info at phpclasses dot org.