summaryrefslogtreecommitdiff
path: root/scripts/commandline.inc
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-06-29 13:23:45 -0700
committerZach Copley <zach@controlyourself.ca>2009-06-29 13:23:45 -0700
commitdd1fc46f0986e5675d24208199b88150f643925d (patch)
treeb19ecc1c4f60882f5cc231214398e57190d6ce14 /scripts/commandline.inc
parentf65015b24a8448ecbb12b3897992cdaf6b563212 (diff)
parent5b8e40aaa9bdb0c07cce0cf53cd913b0c397fdc4 (diff)
Merge branch '0.8.x' into design_reset
* 0.8.x: (32 commits) admin indicators in groups show section with admins in sidebar of group update to latest (r76) version of XMPPHP better output for common error handler fix logging error note when going background change name of constructor for xmppdaemon add a lot more logging to xmppdaemon error in get_option_value wasn't returning a value reformat commandline.inc if not in daemon mode, xmppdaemon sends log to stdout extract log-line formatting to its own function got my background/foreground logic backwards twitter status fetcher takes an id argument more efficient fixup of conversations commandline processing handles errors better xmppdaemon.php can stay in foreground command line arg handling a little more flexible Daemon can optionally not go into the background don't canonicalize people's text into URLs ... Conflicts: theme/base/css/display.css
Diffstat (limited to 'scripts/commandline.inc')
-rw-r--r--scripts/commandline.inc84
1 files changed, 60 insertions, 24 deletions
diff --git a/scripts/commandline.inc b/scripts/commandline.inc
index 4a7757fb9..3b6ef6098 100644
--- a/scripts/commandline.inc
+++ b/scripts/commandline.inc
@@ -63,14 +63,21 @@ if (isset($longoptions)) {
$parser = new Console_Getopt();
-list($options, $args) = $parser->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 = <<<END_OF_DEFAULT
-General options:
+ General options:
-q --quiet Quiet (little output)
-v --verbose Verbose (lots of output)
@@ -80,11 +87,11 @@ General options:
-h --help Show this message and quit.
END_OF_DEFAULT;
- if (isset($helptext)) {
- print $helptext;
- }
- print $_default_help_text;
- exit(0);
+ if (isset($helptext)) {
+ print $helptext;
+ }
+ print $_default_help_text;
+ exit(0);
}
foreach ($options as $option) {
@@ -115,24 +122,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;
+}