From 092d5cadb790d0c32c22316997577c3f9c885fff Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 4 Mar 2012 23:05:44 +0000 Subject: [PATCH] make file an argument, --title is script specific --file did not make that many sense, it is easier to just pass the filename as an argument Call to parent constructor was misplaced, that made the script specific options pretends they were generic maintenance parameters. --- maintenance/parse.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/maintenance/parse.php b/maintenance/parse.php index 2090eb87ca..ec5aba14fb 100644 --- a/maintenance/parse.php +++ b/maintenance/parse.php @@ -14,8 +14,8 @@ * * Example2: * @code - * $ echo "'''bold'''" > /tmp/foo - * $ php parse.php --file /tmp/foo + * $ echo "'''bold'''" > /tmp/foo.txt + * $ php parse.php /tmp/foo.txt *

bold *

$ * @endcode @@ -37,10 +37,10 @@ class CLIParser extends Maintenance { protected $parser; public function __construct() { + parent::__construct(); $this->mDescription = "Parse a given wikitext"; $this->addOption( 'title', 'Title name for the given wikitext (Default: \'CLIParser\')', false, true ); - $this->addOption( 'file', 'File containing wikitext (Default: stdin)', false, true ); - parent::__construct(); + $this->addArg( 'file', 'File containing wikitext (Default: stdin)', false ); } public function execute() { @@ -57,13 +57,19 @@ class CLIParser extends Maintenance { } /** - * Get wikitext from --file or from STDIN + * Get wikitext from a the file passed as argument or STDIN * @return string Wikitext */ protected function Wikitext() { - return file_get_contents( - $this->getOption( 'file', 'php://stdin' ) - ); + + $php_stdin = 'php://stdin'; + $input_file = $this->getArg( 0, $php_stdin ); + + if( $input_file === $php_stdin ) { + fwrite( STDERR, basename(__FILE__) .": warning: reading wikitext from STDIN\n" ); + } + + return file_get_contents( $input_file ); } protected function initParser() { -- 2.20.1