reformat commandline.inc
This commit is contained in:
parent
25c721f6ff
commit
7a0d33ab5f
@ -66,10 +66,10 @@ $parser = new Console_Getopt();
|
|||||||
$result = $parser->getopt($argv, $shortoptions, $longoptions);
|
$result = $parser->getopt($argv, $shortoptions, $longoptions);
|
||||||
|
|
||||||
if (PEAR::isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
print $result->getMessage()."\n";
|
print $result->getMessage()."\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
list($options, $args) = $result;
|
list($options, $args) = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_help()
|
function show_help()
|
||||||
@ -77,7 +77,7 @@ function show_help()
|
|||||||
global $helptext;
|
global $helptext;
|
||||||
|
|
||||||
$_default_help_text = <<<END_OF_DEFAULT
|
$_default_help_text = <<<END_OF_DEFAULT
|
||||||
General options:
|
General options:
|
||||||
|
|
||||||
-q --quiet Quiet (little output)
|
-q --quiet Quiet (little output)
|
||||||
-v --verbose Verbose (lots of output)
|
-v --verbose Verbose (lots of output)
|
||||||
@ -87,11 +87,11 @@ General options:
|
|||||||
-h --help Show this message and quit.
|
-h --help Show this message and quit.
|
||||||
|
|
||||||
END_OF_DEFAULT;
|
END_OF_DEFAULT;
|
||||||
if (isset($helptext)) {
|
if (isset($helptext)) {
|
||||||
print $helptext;
|
print $helptext;
|
||||||
}
|
}
|
||||||
print $_default_help_text;
|
print $_default_help_text;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
@ -124,58 +124,58 @@ set_error_handler('common_error_handler');
|
|||||||
|
|
||||||
function have_option($opt, $alt=null)
|
function have_option($opt, $alt=null)
|
||||||
{
|
{
|
||||||
global $options;
|
global $options;
|
||||||
|
|
||||||
$matches = array($opt);
|
$matches = array();
|
||||||
|
|
||||||
if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
|
if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
|
||||||
$matches[] = '--'.$opt;
|
$matches[] = '--'.$opt;
|
||||||
} else {
|
} else {
|
||||||
$matches[] = $opt;
|
$matches[] = $opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($alt)) {
|
if (!empty($alt)) {
|
||||||
if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
|
if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
|
||||||
$matches[] = '--'.$alt;
|
$matches[] = '--'.$alt;
|
||||||
} else {
|
} else {
|
||||||
$matches[] = $alt;
|
$matches[] = $alt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
if (in_array($option[0], $matches)) {
|
if (in_array($option[0], $matches)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_option_value($str, $alt=null)
|
function get_option_value($str, $alt=null)
|
||||||
{
|
{
|
||||||
global $options;
|
global $options;
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
|
|
||||||
if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
|
if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
|
||||||
$matches[] = '--'.$opt;
|
$matches[] = '--'.$opt;
|
||||||
} else {
|
} else {
|
||||||
$matches[] = $opt;
|
$matches[] = $opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($alt)) {
|
if (!empty($alt)) {
|
||||||
if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
|
if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
|
||||||
$matches[] = '--'.$alt;
|
$matches[] = '--'.$alt;
|
||||||
} else {
|
} else {
|
||||||
$matches[] = $alt;
|
$matches[] = $alt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
if (in_array($option[0], $matches)) {
|
if (in_array($option[0], $matches)) {
|
||||||
return $option[1];
|
return $option[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user