1 | <?php |
||||
2 | /** |
||||
3 | * Basic.php |
||||
4 | * |
||||
5 | * Run this script like |
||||
6 | * |
||||
7 | * $ php ./basic.php -p=abc --user=abcd |
||||
8 | * |
||||
9 | * PHP version 7.3 and up. |
||||
10 | * |
||||
11 | * @category Core |
||||
12 | * @package Redbox_Cli |
||||
13 | * @author Johnny Mast <[email protected]> |
||||
14 | * @license https://opensource.org/licenses/MIT MIT |
||||
15 | * @link https://github.com/johnnymast/redbox-cli |
||||
16 | * @since 1.0 |
||||
17 | */ |
||||
18 | |||||
19 | require 'autoload.php'; |
||||
20 | |||||
21 | use Redbox\Cli\Cli as CLI; |
||||
22 | |||||
23 | /** |
||||
24 | * Run this script like |
||||
25 | * |
||||
26 | * $ php ./basic.php -p=abc --user=abcd |
||||
27 | */ |
||||
28 | try { |
||||
29 | $cli = new CLI; |
||||
30 | |||||
31 | /** |
||||
32 | * Setup the rules of engagement |
||||
33 | */ |
||||
34 | $cli->arguments->add( |
||||
35 | [ |
||||
36 | 'user' => [ |
||||
37 | 'prefix' => 'u', |
||||
38 | 'longPrefix' => 'user', |
||||
39 | 'description' => 'Username', |
||||
40 | 'defaultValue' => 'me_myself_i', |
||||
41 | 'required' => true, |
||||
42 | ], |
||||
43 | 'password' => [ |
||||
44 | 'prefix' => 'p', |
||||
45 | 'longPrefix' => 'password', |
||||
46 | 'description' => 'Password', |
||||
47 | 'required' => true, |
||||
48 | ], |
||||
49 | 'iterations' => [ |
||||
50 | 'prefix' => 'i', |
||||
51 | 'longPrefix' => 'iterations', |
||||
52 | 'description' => 'Number of iterations', |
||||
53 | ], |
||||
54 | 'verbose' => [ |
||||
55 | 'prefix' => 'v', |
||||
56 | 'longPrefix' => 'verbose', |
||||
57 | 'description' => 'Verbose output', |
||||
58 | 'noValue' => true, |
||||
59 | ], |
||||
60 | 'help' => [ |
||||
61 | 'longPrefix' => 'help', |
||||
62 | 'description' => 'Prints a usage statement', |
||||
63 | 'noValue' => true, |
||||
64 | ], |
||||
65 | 'path' => [/* NOT YET SUPPORTED */ |
||||
66 | 'description' => 'The path to push', |
||||
67 | ], |
||||
68 | ] |
||||
69 | ); |
||||
70 | |||||
71 | /** |
||||
72 | * We need to tell the parser to start. |
||||
73 | */ |
||||
74 | $cli->arguments->parse(); |
||||
75 | |||||
76 | /** |
||||
77 | * If we don't get an exception of us missing things we can handle stuff. |
||||
78 | */ |
||||
79 | echo "You entered password: ".$cli->arguments->get('password')."\n"; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
80 | echo "You entered username: ".$cli->arguments->get('user')."\n"; |
||||
0 ignored issues
–
show
Are you sure
$cli->arguments->get('user') of type false|mixed can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
81 | |||||
82 | } catch (Exception $e) { |
||||
83 | /** |
||||
84 | * Print how to use the script |
||||
85 | */ |
||||
86 | $cli->arguments->usage(); |
||||
87 | } |
||||
88 |