Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
/ php-cli Public archive

Build command line tools using PHP

License

Notifications You must be signed in to change notification settings

aubreypwd-old/php-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aubreypwd/php-cli

This is a CLI-tool I use to write command line tools using PHP. It's a wrapper for splitbrain/php-cli that adds some tools and improvements I enjoy having, like:

  1. HTML-like tags for bullets, paragraphs, break-returns, and colorization
  2. A log() method that's more powerful than the built in info, error, etc methods from splitbrain/php-cli
  3. Tools like has_command(), get_php_version(), rid() (run in directory), etc
  4. Easier ways to run shell commands and extrapolate results including status, output (array|string), etc, with or without stderr (see aubreypwd\PHP_CLI\Command::exec())

...and more.

The best way to familiarize yourself with what you can do see:

The both should document and examplify use-cases until I build more tools with it.

Installation

composer require aubreypwd/php-cli

Tips & Tricks

Avoid un-explained options from being thrown as Exceptions

To avoid un-explained options from being thrown as \Exception's run ::run() with a try/catch like so:

namespace aubreypwd\My_CLI;

final class Command extends \aubreypwd\PHP_CLI\Command {
	...
}

$cli = new \aubreypwd\My_CLI\Command();

try {

	$cli->run();

} catch ( \Exception $e ) {

	$cli->log( 'error', "{$e->getMessage()}\n" );
}

splitbrain/php-cli shows an odd message when you try to use an option like --option|-o that has not been explained.