PHPackages                             duanejeffers/cli.class.php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. duanejeffers/cli.class.php

ActiveLibrary[CLI &amp; Console](/categories/cli)

duanejeffers/cli.class.php
==========================

Simple object for creating CLI programs in PHP

3731[2 issues](https://github.com/duanejeffers/cli.class.php/issues)PHP

Since Apr 25Pushed 11y ago1 watchersCompare

[ Source](https://github.com/duanejeffers/cli.class.php)[ Packagist](https://packagist.org/packages/duanejeffers/cli.class.php)[ RSS](/packages/duanejeffers-cliclassphp/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

cli.class.php
=============

[](#cliclassphp)

Class for Commandline PHP applications

LICENSE
-------

[](#license)

Copyright (c) 2012-2013, Duane Jeffers &lt;&gt;

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

USAGE
-----

[](#usage)

The purpose for the cli object is to provide quick access to the common functions for a cli script/program.

### Starting the object

[](#starting-the-object)

```
// Starting the cli class is easy...
$cli = new cli();

// Printing with a carrage return
$cli->print_line('Welcome to cli.class.php');

// Dumping an object or array to the screen with a carrage return.
$array = array(
    0 => array(
      'maple',
      'blueberry'
	),
	1 => array(
	    'pancakes',
		'waffles'
	)
);

$cli->print_dump($array);
```

### Color Output

[](#color-output)

```
// The class has the default color options for the terminal.
// Use the color_str static function to create the string.

$output = 'This is ';
$output .= cli::color_str('a ', cli::ColorFgLtRed);
$output .= cli::color_str('color ', cli::ColorFgBlue);
$output .= cli::color_str('string', cli::ColorFgBlack, cli::ColorBgLtGray);
$output .= cli::color_str('!!!', cli::ColorFgLtGreen);

$cli->print_line($output);
```

### Option Handling

[](#option-handling)

```
// Options with the cli object are as simple as passing
// an array through the constructor.
$cli = new cli(array(
    'email:' => 'Email Address', // option that requires an input
    'username::' => 'Username', // option that allows for an optional input
    'download' => 'Download switch' // option that acts as a bool switch
));

// Now, when the user calls
//  --email=someemail@test.com --download --username
// This will auto-populate an options array, and allow you to access it
// using the cli->opt() function.

if($cli->opt('download')) { // To see if the option isset, returns a bool

// If an option has an input, you can return the input by passing TRUE
// in the second parameter.
    $url .= '&email=' . $cli->opt('email', TRUE);
}

// To help users with a list of available options, cli->print_help()
// prints a help table with a message.
$cli = new cli(array('h' => 'Show Options', 'help' => 'Show Help and Quit'));

$cli->print_help('h'); // print_help can be tied to a single option call.

// This is a full help call, with header text (arg 2), and then a die() call. (arg 3).
$cli->print_help('help', "This is the complete system's options to call", TRUE);

// Loading Options From A Configuration File
```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance7

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/67160bfec122897dbd4b1e6c3983a5392501628989d41e34a319abdeb1af88d9?d=identicon)[duanejeffers](/maintainers/duanejeffers)

---

Top Contributors

[![duanejeffers](https://avatars.githubusercontent.com/u/684454?v=4)](https://github.com/duanejeffers "duanejeffers (20 commits)")

### Embed Badge

![Health badge](/badges/duanejeffers-cliclassphp/health.svg)

```
[![Health](https://phpackages.com/badges/duanejeffers-cliclassphp/health.svg)](https://phpackages.com/packages/duanejeffers-cliclassphp)
```

###  Alternatives

[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24726.4M22](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

13045.3M6.2k](/packages/illuminate-console)[styleci/cli

The CLI tool for StyleCI

71464.1k9](/packages/styleci-cli)[winbox/args

Windows command-line formatter

20718.9k21](/packages/winbox-args)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
