-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.php
66 lines (50 loc) · 1.94 KB
/
utils_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
include_once "vendor/autoload.php";
use Diversen\Cli\Utils;
$settings = [
'colorError' => 'red',
'colorSuccess' => 'green',
'colorNotice' => 'yellow',
];
$utils = new Utils($settings);
// Exectuing a command and display a status message [OK] ls -l");
// Res is the shell result of the command. Normally 0 on success.
$res = $utils->execSilent('ls -l test && ls -l iwqeruoiiqower');
if ($res !== 0) {
// Last part of the command should give an error 'ls -l iwqeruoiiqower'
echo $utils->colorOutput("Some error occured\n", 'error');
echo $utils->getStderr(). "\n";
}
// Stdout output
echo $utils->colorOutput("Stdout output from command\n", 'notice');
echo $utils->getStdout() . "\n";
// Check if in console
if ($utils->isCli()) {
echo ("You are in a console\n");
}
// Check if user is root
if ($utils->isRoot()) {
echo $utils->colorOutput("You are root\n", 'notice');
} else {
echo $utils->colorOutput ("You are not root\n", 'error');
}
// Built in colors
echo $notice_str = $utils->colorOutput("Built-in notice color\n", 'notice');
echo $success_str = $utils->colorOutput("Built-in success color\n", 'success');
echo $error_str = $utils->colorOutput("Built-in error color\n", 'error');
// Output a green string
$green_str = $utils->colorOutput('Test green', 'green');
echo $green_str . "\n";
// Output a green string
$green_str = $utils->colorOutput('Test default');
echo $green_str . "\n";
// First part of the command should be ok 'ls -l test'
echo $utils->getStdout() . "\n";
// Prompt the user for input
$line = $utils->readSingleline('Command will read a line: ');
echo $utils->colorOutput("You wrote $line\n");
// Prompt for yes or no
$answer = $utils->readlineConfirm('Are you sure you want to continue: ');
echo $utils->colorOutput("You answer evaluates to $answer\n");
$res = $utils->needRoot("If you are not root we will now exit");
echo $utils->colorOutput("$res is the status of the \$utils->needRoot method\n");