Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

php-cli-class

A PHP CLI (Command Line Interface) for you to run PHP CLI easily with little fuss over the complexity

Adding options

Adding options for use with cli is easy just call

$this->addOption("test1","t",":","some description of this param.");
ParamDescription
test1is the long name of the cli param used
tis the short name of the cli param used
:denotes value required param types can be;
"" no value needed
":" value required
"::" value not required
some...is the description of the param used

Calling Options

calling an option is easy use this function to return the param NOTE: default return is null as no value option return false if present so null is used

$this->getOption("test1")

Example Class

<?php//example-cli.phpinclude("cli.class.php");
class exampleAPI extendsCLI
{
publicfunction__construct()
{
$this->setInfo("This is my TEST CLI file and this is all about it.");
$this->addOptions("timer", "t", "", "this is a timer");
$this->addOptions("test1", "a", "", "this is a test param option");
$this->addOptions("test2", "b", ":", "this is a test param with value requires option");
$this->addOptions("test3", "c", "::", "this is a test param with value optional option");
}
publicfunctionMain()
{
$this->read();
if (!$this->hasOptions()) {
$this->help();
}
if ($this->getOption("test1") !== null) {
echo$this->line("You just ran test 1 param");
}
if ($this->getOption("test2") !== null) {
echo$this->line("You just ran test 2 param with value: ".$this->getOption("test2"));
}
if ($this->getOption("test3") !== null) {
echo$this->line("You just ran test 3 param with optional value: ".$this->getOption("test3"));
}
if ($this->getOption("timer") !== null) {
for ($i=1; $i<=10; $i++) {
echo$this->line("You just ran timer with {$i}s passed.");
sleep(1);
}
}
}
}

Example Usage

<?php//cli.phpinclude("example-cli.php");
$cli = newexampleAPI();
$cli->Main();

CLI Usage

 C:\User php cli.php -t
C:\User php cli.php -timer
C:\User php cli.php -test1="your value"
C:\User php cli.php -a="your value"
C:\User php cli.php -a -b=this -c=that
C:\User php cli.php --test1 --test2=this --test3=that
C:\User php cli.php -a

About

A PHP CLI (Command Line Interface) for you to run PHP CLI easily with little fuss over the complexity

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages