1 | <?php |
||
2 | /** |
||
3 | * Defaultvalue.php |
||
4 | * |
||
5 | * To see the different results run this script like. |
||
6 | * |
||
7 | * $ php ./defaultvalue.php |
||
8 | * OR |
||
9 | * php ./defaultvalue.php -t=X |
||
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 | require 'autoload.php'; |
||
21 | |||
22 | use Redbox\Cli\Cli as CLI; |
||
23 | |||
24 | try { |
||
25 | $cli = new CLI; |
||
26 | |||
27 | /** |
||
28 | * Setup the rules of engagement |
||
29 | */ |
||
30 | $cli->arguments->add( |
||
31 | [ |
||
32 | 'targetpath' => [ |
||
33 | 'prefix' => 't', |
||
34 | 'longPrefix' => 'targetpath', |
||
35 | 'description' => 'Path', |
||
36 | 'defaultValue' => '/var/log', |
||
37 | 'required' => true, |
||
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 "The default value for path is: " . $cli->arguments->get('targetpath') . "\n"; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
51 | |||
52 | } catch (Exception $e) { |
||
53 | /** |
||
54 | * Print how to use the script |
||
55 | */ |
||
56 | $cli->arguments->usage(); |
||
57 | } |
||
58 |