This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse-cmdline.php
87 lines (76 loc) · 2.73 KB
/
parse-cmdline.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* FlexiPeeHP Bricks - Commandline parameters parser
*
* @author Vítězslav Dvořák <info@vitexsofware.cz>
* @copyright (G) 2018 Vitex Software
*/
/**
* Parse Commandline
*
* @return array
*/
function parseCmdline()
{
$optionsParsed = [];
$shortopts = "";
$shortopts .= "s:"; // Server
$shortopts .= "u:"; // Username
$shortopts .= "p:"; // Password
$shortopts .= "c:"; // Company
$shortopts .= "f:"; // Config
$shortopts .= "d"; // Debug
$longopts = array(
"server:", // Server
"username:", // Username
"password:", // Password
"company:", // Company
"file:", // Config file
"debug", // Debug
);
$options = getopt($shortopts, $longopts);
if (array_key_exists('s', $options)) {
$optionsParsed['url'] = $options['s'];
}
if (array_key_exists('server', $options)) {
$optionsParsed['url'] = $options['server'];
}
if (array_key_exists('c', $options)) {
$optionsParsed['company'] = $options['c'];
}
if (array_key_exists('company', $options)) {
$optionsParsed['company'] = $options['company'];
}
if (array_key_exists('u', $options)) {
$optionsParsed['user'] = $options['u'];
}
if (array_key_exists('user', $options)) {
$optionsParsed['user'] = $options['user'];
}
if (array_key_exists('p', $options)) {
$optionsParsed['password'] = $options['p'];
}
if (array_key_exists('password', $options)) {
$optionsParsed['password'] = $options['password'];
}
if (array_key_exists('f', $options)) {
$optionsParsed['config'] = $options['f'] ? $options['f'] : '/etc/flexibee/client.json';
}
if (array_key_exists('file', $options)) {
$optionsParsed['config'] = $options['file'] ? $options['file'] : '/etc/flexibee/client.json';
}
if (array_key_exists('config', $optionsParsed)) {
\Ease\Shared::instanced()->loadConfig($optionsParsed['config'],true);
}
if (array_key_exists('d', $options)) {
$optionsParsed['debug'] = true;
}
if (array_key_exists('debug', $options)) {
$optionsParsed['debug'] = true;
}
if ((count($optionsParsed) < 4) && !array_key_exists('config',
$optionsParsed)) {
echo("Usage: ".basename($_SERVER['SCRIPT_NAME'])." -s https://SERVER[:PORT] -u USERNAME -p PASSWORD -c COMPANY [-d debug]\n");
}
return $optionsParsed;
}