johnnymast /
redbox-cli
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Hasdefaultvalue.php |
||
| 4 | * |
||
| 5 | * Run this script like |
||
| 6 | * |
||
| 7 | * $ php ./hasdefaultvalue.php |
||
| 8 | * OR |
||
| 9 | * $ php ./hasdefaultvalue.php --targetpath=/var |
||
| 10 | * |
||
| 11 | * PHP version 7.3 and up. |
||
| 12 | * |
||
| 13 | * @category Core |
||
| 14 | * @package Redbox_Cli |
||
| 15 | * @author Johnny Mast <[email protected]> |
||
| 16 | * @license https://opensource.org/licenses/MIT MIT |
||
| 17 | * @link https://github.com/johnnymast/redbox-cli |
||
| 18 | * @since 1.0 |
||
| 19 | */ |
||
| 20 | |||
| 21 | require 'autoload.php'; |
||
| 22 | |||
| 23 | use Redbox\Cli\Cli as CLI; |
||
| 24 | |||
| 25 | try { |
||
| 26 | $cli = new CLI; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Setup the rules of engagement |
||
| 30 | */ |
||
| 31 | $cli->arguments->add( |
||
| 32 | [ |
||
| 33 | 'targetpath' => [ |
||
| 34 | 'prefix' => 't', |
||
| 35 | 'longPrefix' => 'targetpath', |
||
| 36 | 'description' => 'Path', |
||
| 37 | 'defaultValue' => '/var/log', |
||
| 38 | ] |
||
| 39 | ] |
||
| 40 | ); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * We need to tell the parser to start. |
||
| 44 | */ |
||
| 45 | $cli->arguments->parse(); |
||
| 46 | |||
| 47 | /** |
||
| 48 | * If we don't get an exception of us missing things we can handle stuff. |
||
| 49 | */ |
||
| 50 | echo "You entered path: " . $cli->arguments->get('targetpath') . "\n"; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 51 | echo "Is this the default value?: " . ($cli->arguments->hasDefaultValue('targetpath') ? 'Yes' : 'No') . "\n"; |
||
| 52 | |||
| 53 | } catch (Exception $e) { |
||
| 54 | /** |
||
| 55 | * Print how to use the script |
||
| 56 | */ |
||
| 57 | $cli->arguments->usage(); |
||
| 58 | } |
||
| 59 |