X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fcommandline.inc;h=9029bb19db4e7df9879d73fccbb4b792124c8599;hb=42463e160d6672f6e5e458a22ddae79b62fa39bf;hp=8da42873a2145af99a4c8d0c3ffa571f924e84e4;hpb=a81350f6559a59921443d9773eccc9f8cfd96ee1;p=quix0rs-gnu-social.git diff --git a/scripts/commandline.inc b/scripts/commandline.inc index 8da42873a2..9029bb19db 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -1,7 +1,7 @@ getopt($argv, $shortoptions, $longoptions); +$result = $parser->getopt($argv, $shortoptions, $longoptions); + +if (PEAR::isError($result)) { + print $result->getMessage()."\n"; + exit(1); +} else { + list($options, $args) = $result; +} + +function show_help() +{ + global $helptext; + + $_default_help_text = << Use as config file + -s --server= Use as server name + -p --path= Use as path name + -h --help Show this message and quit. + +END_OF_DEFAULT; + if (isset($helptext)) { + print $helptext; + } + print $_default_help_text; + exit(0); +} foreach ($options as $option) { switch ($option[0]) { case '--server': - case '-s': + case 's': $server = $option[1]; break; case '--path': - case '-p': + case 'p': $path = $option[1]; break; case '--conf': - case '-c': + case 'c': $conffile = $option[1]; break; case '--help': - case '-h': - $_default_help_text = << Use as config file - -s --server= Use as server name - -p --path= Use as path name - -h --help Show this message and quit. - -END_OF_DEFAULT; - if (isset($helptext)) { - print $helptext; - } - print $_default_help_text; - exit(0); + case 'h': + show_help(); } } @@ -108,24 +123,53 @@ require_once INSTALLDIR . '/lib/common.php'; set_error_handler('common_error_handler'); -function have_option($str) +function _make_matches($opt, $alt) { - global $options; - foreach ($options as $option) { - if ($option[0] == $str) { - return true; - } - } - return false; + $matches = array(); + + if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { + $matches[] = '--'.$opt; + } else { + $matches[] = $opt; + } + + if (!empty($alt)) { + if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { + $matches[] = '--'.$alt; + } else { + $matches[] = $alt; + } + } + + return $matches; } -function get_option_value($str) +function have_option($opt, $alt=null) { - global $options; - foreach ($options as $option) { - if ($option[0] == $str) { - return $option[1]; - } - } - return null; -} \ No newline at end of file + global $options; + + $matches = _make_matches($opt, $alt); + + foreach ($options as $option) { + if (in_array($option[0], $matches)) { + return true; + } + } + + return false; +} + +function get_option_value($opt, $alt=null) +{ + global $options; + + $matches = _make_matches($opt, $alt); + + foreach ($options as $option) { + if (in_array($option[0], $matches)) { + return $option[1]; + } + } + + return null; +}