php-cli-tools
Tools
PHP
PHP Command Line Tools
A collection of functions and classes to assist with command line development.
Requirements
- PHP >= 5.3
Suggested PHP extensions
- mbstring – Used for calculating string widths.
Function List
-
cliout($msg, ...)
-
cliout_padded($msg, ...)
-
clierr($msg, ...)
-
cliline($msg = '', ...)
-
cliinput()
-
cliprompt($question, $default = false, $marker=":")
-
clichoose($question, $choices="yn", $default="n")
-
climenu($items, $default = false, $title="Choose an Item")
Progress Indicators
-
clinotifyDots($msg, $dots = 3, $interval = 100)
-
clinotifySpinner($msg, $interval = 100)
-
cliprogressBar($msg, $total, $interval = 100)
Tabular Display
-
cliTable::__construct(array $headers = null, array $rows = null)
-
cliTable::setHeaders(array $headers)
-
cliTable::setRows(array $rows)
-
cliTable::setRenderer(clitableRenderer $renderer)
-
cliTable::addRow(array $row)
-
cliTable::sort($column)
-
cliTable::display()
The display function will detect if output is piped and, if it is, render a tab delimited table instead of the ASCII
table rendered for visual display.
You can also explicitly set the renderer used by calling cliTable::setRenderer()
and giving it an instance of one
of the concrete clitableRenderer
classes.
Tree Display
-
cliTree::__construct()
-
cliTree::setData(array $data)
-
cliTree::setRenderer(clitreeRenderer $renderer)
-
cliTree::render()
-
cliTree::display()
Argument Parser
Argument parsing uses a simple framework for taking a list of command line arguments,
usually straight from $_SERVER['argv']
, and parses the input against a set of
defined rules.
Check examples/arguments.php
for an example.
Usage
See examples/
directory for examples.
Todo
- Expand this README
- Add doc blocks to rest of code