GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - czproject/phpcli: Helper class for PHP CLI apps.

BranchesTags
Open more actions menu

Latest commit

 

History

145 Commits
145 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
Makefile
Makefile
 
 
code-checker.neon
code-checker.neon
 
 
composer.json
composer.json
 
 
license.md
license.md
 
 
phpstan.neon
phpstan.neon
 
 
readme.md
readme.md
 
 

Repository files navigation

PHP CLI Console

Build Status Downloads this Month Latest Stable Version License

Donate

Installation

Download a latest package or use Composer:

composer require czproject/phpcli

PhpCli requires PHP 8.0 or later, optionaly Readline extension.

Usage

use CzProject\PhpCli\ConsoleFactory;

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

$console = ConsoleFactory::createConsole();

// output
$console->output('CzProject CLI Simple Console', 'green')
	->nl() // new line
	->output('Hey!', 'yellow')
	->nl()
	->output('Fred!', 'blue')
	->nl()
	->output('Fred is dead!', 'red')
	->nl()
	->output(['nooooooo...!', ' ', 'But, no problem!'], 'gray')
	->nl()
	->output('The end.')
	->nl();

// input
$username = $console->input('Enter your name');

$console->output('Hello! ', 'blue')
	->output($username, 'green')
	->output(' [user]', 'yellow')
	->nl() // print new line
	->output('Bye!', 'blue')
	->nl();

// input with default value
$username = $console->input('Enter your name', 'John');

// confirm
$agree = $console->confirm('Do you want to continue?');

// confirm with default value
$canQuit = $console->confirm('Really?', TRUE);

// select
$value = $console->select('Select color:', [
	'value' => 'label',
	'#ff0000' => 'Red',
	'#00ff00' => 'Green',
	'#0000ff' => 'Blue',
]);

// select with default value
$value = $console->select('Select color:', [
	'value' => 'label',
	'#ff0000' => 'Red',
	'#00ff00' => 'Green',
	'#0000ff' => 'Blue',
], '#ff0000');

Parameters

Arguments

$name = $console->getArgument(0)->getValue(); // string|NULL

$size = $console->getArgument(1, 'int')
	->setRequired()
	->addRule(function ($value) {
		return $value > 0;
	})
	->getValue();

$price = $console->getArgument(2, 'float') // float
	->setDefaultValue(100.0)
	->getValue();

Options

$name = $console->getOption('name')->getValue(); // string|NULL

$size = $console->getOption('size', 'int')
	->setRequired()
	->addRule(function ($value) {
		return $value > 0;
	})
	->getValue();

$price = $console->getOption('price', 'float') // float
	->setDefaultValue(100.0)
	->getValue();

$words = $console->getOption('word')
	->setRepeatable()
	->getValue();

Supported types

  • string
  • int and integer
  • float
  • bool and boolean

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/

About

Helper class for PHP CLI apps.

Topics

phpphp-cli

Resources

Readme
License
Activity
Custom properties

Stars

7 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.