Add ArgvParser
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 9 Nov 2012 22:12:20 +0000 (23:12 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 9 Nov 2012 22:12:20 +0000 (23:12 +0100)
wcfsetup/install/files/lib/system/CLIWCF.class.php

index 2b321de390bc12334558f2fe4304835fd67908e3..a5bc4b9ddbfd8eacca0ebed2646c4a75a8ed0900 100644 (file)
@@ -9,6 +9,7 @@ use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\UserInputException;
 use wcf\system\user\authentication\UserAuthenticationFactory;
 use wcf\util\StringUtil;
+use Zend\Console\Getopt as ArgvParser;
 use Zend\Loader\StandardAutoloader as ZendLoader;
 
 /**
@@ -40,10 +41,28 @@ class CLIWCF extends WCF {
                $zendLoader = new ZendLoader(array(ZendLoader::AUTOREGISTER_ZF => true));
                $zendLoader->register();
                
+               $this->initArgv();
                $this->initPHPLine();
                $this->initAuth();
        }
        
+       /**
+        * Initializes parsing of command line options.
+        */
+       protected function initArgv() {
+               $opts = new ArgvParser(array(
+                       'v' => 'Verbose: Show more output',
+                       'q' => 'Quiet: Show less output',
+                       'h|help' => 'Show this help'
+               ));
+               $opts->setOptions(array(ArgvParser::CONFIG_CUMULATIVE_FLAGS => true));
+               $opts->parse();
+               if ($opts->getOption('help')) {
+                       echo $opts->getUsageMessage();
+                       exit;
+               }
+       }
+       
        /**
         * Initializes PHPLine.
         */