Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/57827


Change subject: Move Args class to a separate file
......................................................................

Move Args class to a separate file

Change-Id: I65921bea9092688d1e05285aa819f566a45dcb30
---
A includes/Args.php
M stylize.php
2 files changed, 80 insertions(+), 73 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/code-utils 
refs/changes/27/57827/1

diff --git a/includes/Args.php b/includes/Args.php
new file mode 100644
index 0000000..d47d630
--- /dev/null
+++ b/includes/Args.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * From:
+ * - http://code.google.com/p/tylerhall/source/browse/trunk/class.args.php
+ * - http://clickontyler.com/blog/2008/11/parse-command-line-arguments-in-php/ 
(MIT license)
+ *
+ * Copyright (c) 2008 Tyler Hall
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE
+ */
+class Args {
+       public $flags;
+       public $args;
+
+       public function __construct( $argv ) {
+               $this->flags = array();
+               $this->args  = array();
+
+               for ( $i = 0; $i < count( $argv ); $i++ ) {
+                       $str = $argv[$i];
+
+                       // --foo
+                       if ( strlen( $str ) > 2 && substr( $str, 0, 2 ) == '--' 
) {
+                               $str = substr( $str, 2 );
+                               $parts = explode( '=', $str );
+                               $this->flags[$parts[0]] = true;
+
+                               // Does not have an =, so choose the next arg 
as its value
+                               if ( count( $parts ) == 1 && isset( $argv[$i + 
1] ) && preg_match( '/^--?.+/', $argv[$i + 1] ) == 0 ) {
+                                       $this->flags[$parts[0]] = $argv[$i + 1];
+                               } elseif ( count( $parts ) == 2 ) {
+                                       // Has a =, so pick the second piece
+                                       $this->flags[$parts[0]] = $parts[1];
+                               }
+                       // -a
+                       } elseif ( strlen( $str ) == 2 && $str[0] == '-' ) {
+                               $this->flags[$str[1]] = true;
+                               if ( isset( $argv[$i + 1] ) && preg_match( 
'/^--?.+/', $argv[$i + 1] ) == 0 )
+                                       $this->flags[$str[1]] = $argv[$i + 1];
+                       // -abcdef
+                       } elseif ( strlen( $str ) > 1 && $str[0] == '-' ) {
+                               for ( $j = 1; $j < strlen( $str ); $j++ )
+                                       $this->flags[$str[$j]] = true;
+                       }
+               }
+
+               // Any arguments after the last - or --
+               for ( $i = count( $argv ) - 1; $i >= 0; $i-- ) {
+                       if ( preg_match( '/^--?.+/', $argv[$i] ) == 0 )
+                               $this->args[] = $argv[$i];
+                       else
+                               break;
+               }
+
+               $this->args = array_reverse( $this->args );
+       }
+
+       public function flag( $name ) {
+               return isset( $this->flags[$name] ) ? $this->flags[$name] : 
false;
+       }
+}
diff --git a/stylize.php b/stylize.php
index a8eed38..acaf40a 100755
--- a/stylize.php
+++ b/stylize.php
@@ -7,7 +7,10 @@
  *
  * @author Tim Starling
  * @author Jeroen De Dauw
+ * @file
  */
+
+require_once( __DIR__ . '/includes/Args.php' );
 
 if ( php_sapi_name() != 'cli' ) {
        echo "This script must be run from the command line\n";
@@ -324,78 +327,5 @@
        function fixWhitespace( $s ) {
                // Fix whitespace at the line end
                return preg_replace( "#[\t ]*\n#", "\n", $s );
-       }
-}
-
-/**
- * From
- * http://code.google.com/p/tylerhall/source/browse/trunk/class.args.php
- * http://clickontyler.com/blog/2008/11/parse-command-line-arguments-in-php/ - 
MIT License
-
-  Copyright (c) 2008 Tyler Hall
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE
- */
-class Args {
-       private $flags;
-       public $args;
-
-       public function __construct( $argv ) {
-               $this->flags = array();
-               $this->args  = array();
-
-               for ( $i = 0; $i < count( $argv ); $i++ ) {
-                       $str = $argv[$i];
-
-                       // --foo
-                       if ( strlen( $str ) > 2 && substr( $str, 0, 2 ) == '--' 
) {
-                               $str = substr( $str, 2 );
-                               $parts = explode( '=', $str );
-                               $this->flags[$parts[0]] = true;
-
-                               // Does not have an =, so choose the next arg 
as its value
-                               if ( count( $parts ) == 1 && isset( $argv[$i + 
1] ) && preg_match( '/^--?.+/', $argv[$i + 1] ) == 0 ) {
-                                       $this->flags[$parts[0]] = $argv[$i + 1];
-                               } elseif ( count( $parts ) == 2 ) { // Has a =, 
so pick the second piece
-                                       $this->flags[$parts[0]] = $parts[1];
-                               }
-                       } elseif ( strlen( $str ) == 2 && $str[0] == '-' ) { // 
-a
-                               $this->flags[$str[1]] = true;
-                               if ( isset( $argv[$i + 1] ) && preg_match( 
'/^--?.+/', $argv[$i + 1] ) == 0 )
-                                       $this->flags[$str[1]] = $argv[$i + 1];
-                       } elseif ( strlen( $str ) > 1 && $str[0] == '-' ) { // 
-abcdef
-                               for ( $j = 1; $j < strlen( $str ); $j++ )
-                                       $this->flags[$str[$j]] = true;
-                       }
-               }
-
-               for ( $i = count( $argv ) - 1; $i >= 0; $i-- ) {
-                       if ( preg_match( '/^--?.+/', $argv[$i] ) == 0 )
-                               $this->args[] = $argv[$i];
-                       else
-                               break;
-               }
-
-               $this->args = array_reverse( $this->args );
-       }
-
-       public function flag( $name ) {
-               return isset( $this->flags[$name] ) ? $this->flags[$name] : 
false;
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/57827
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I65921bea9092688d1e05285aa819f566a45dcb30
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/code-utils
Gerrit-Branch: master
Gerrit-Owner: Krinkle <ttij...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to