]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/commandline.inc
counter in notice/message form uses global variable for max length
[quix0rs-gnu-social.git] / scripts / commandline.inc
index 4a7757fb98f13e43c47bf55cdd0841da848304fd..3b6ef60987185560c280d7554a4d609e41d49ebd 100644 (file)
@@ -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;
+}