Index: trunk/phase3/maintenance/parse.php |
— | — | @@ -14,8 +14,8 @@ |
15 | 15 | * |
16 | 16 | * Example2: |
17 | 17 | * @code |
18 | | - * $ echo "'''bold'''" > /tmp/foo |
19 | | - * $ php parse.php --file /tmp/foo |
| 18 | + * $ echo "'''bold'''" > /tmp/foo.txt |
| 19 | + * $ php parse.php /tmp/foo.txt |
20 | 20 | * <p><b>bold</b> |
21 | 21 | * </p>$ |
22 | 22 | * @endcode |
— | — | @@ -37,10 +37,10 @@ |
38 | 38 | protected $parser; |
39 | 39 | |
40 | 40 | public function __construct() { |
| 41 | + parent::__construct(); |
41 | 42 | $this->mDescription = "Parse a given wikitext"; |
42 | 43 | $this->addOption( 'title', 'Title name for the given wikitext (Default: \'CLIParser\')', false, true ); |
43 | | - $this->addOption( 'file', 'File containing wikitext (Default: stdin)', false, true ); |
44 | | - parent::__construct(); |
| 44 | + $this->addArg( 'file', 'File containing wikitext (Default: stdin)', false ); |
45 | 45 | } |
46 | 46 | |
47 | 47 | public function execute() { |
— | — | @@ -57,13 +57,19 @@ |
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | | - * Get wikitext from --file or from STDIN |
| 61 | + * Get wikitext from a the file passed as argument or STDIN |
62 | 62 | * @return string Wikitext |
63 | 63 | */ |
64 | 64 | protected function Wikitext() { |
65 | | - return file_get_contents( |
66 | | - $this->getOption( 'file', 'php://stdin' ) |
67 | | - ); |
| 65 | + |
| 66 | + $php_stdin = 'php://stdin'; |
| 67 | + $input_file = $this->getArg( 0, $php_stdin ); |
| 68 | + |
| 69 | + if( $input_file === $php_stdin ) { |
| 70 | + fwrite( STDERR, basename(__FILE__) .": warning: reading wikitext from STDIN\n" ); |
| 71 | + } |
| 72 | + |
| 73 | + return file_get_contents( $input_file ); |
68 | 74 | } |
69 | 75 | |
70 | 76 | protected function initParser() { |