'customwiki', 'uri' => $cliOpts['apiURL'] ]; } if ( isset( $cliOpts['addHTMLTemplateParameters'] ) ) { $envOptions['addHTMLTemplateParameters'] = self::booleanOption( $cliOpts['addHTMLTemplateParameters'] ); } if ( isset( $cliOpts['lint'] ) ) { $envOptions['linting'] = true; } return $envOptions; } /** * Parse a boolean option returned by our opts processor. * The strings 'false' and 'no' are also treated as false values. * This allows `--debug=no` and `--debug=false` to mean the same as * `--no-debug`. * * @param bool|string $val * a boolean, or a string naming a boolean value. * @return bool */ public static function booleanOption( $val ): bool { if ( !$val ) { return false; } if ( is_string( $val ) && preg_match( '/^(no|false)$/D', $val ) ) { return false; } return true; } /** * Set the color flags, based on an options object. * * @param array $options options object to use for setting the mode of the 'color' package. * - string|boolean options.color * Whether to use color. * Passing 'auto' will enable color only if stdout is a TTY device. */ public static function setColorFlags( array $options ): void { /** * PORT-FIXME: * if ( $options->color === 'auto' ) { * if ( !$process->stdout->isTTY ) { * $colors->mode = 'none'; * } * } elseif ( !self::booleanOption( $options->color ) ) { * $colors->mode = 'none'; * } */ } /** * PORT-FIXME: Should some of this functionality be moved to OptsProcessor directly? * * Add standard options to script-specific opts * This handles options parsed by `setDebuggingFlags`, * `setTemplatingAndProcessingFlags`, `setColorFlags`, * and standard --help options. * * The `defaults` option is optional, and lets you override * the defaults for the standard options. * * @param array $opts * @param array $defaults * @return array */ public static function addStandardOptions( array $opts, array $defaults = [] ): array { $standardOpts = [ // standard CLI options 'help' => [ 'description' => 'Show this help message', 'boolean' => true, 'default' => false, 'alias' => 'h' ], // handled by `setDebuggingFlags` 'debug' => [ 'description' => 'Provide optional flags. Use --debug=help for supported options' ], 'trace' => [ 'description' => 'Use --trace=help for supported options' ], 'dump' => [ 'description' => 'Dump state. Use --dump=help for supported options' ], // handled by `setTemplatingAndProcessingFlags` 'fetchConfig' => [ 'description' => 'Whether to fetch the wiki config from the server or use our local copy', 'boolean' => true, 'default' => true ], 'fetchTemplates' => [ 'description' => 'Whether to fetch included templates recursively', 'boolean' => true, 'default' => true ], 'fetchImageInfo' => [ 'description' => 'Whether to fetch image info via the API', 'boolean' => true, 'default' => true ], 'expandExtensions' => [ 'description' => 'Whether we should request extension tag expansions from a wiki', 'boolean' => true, 'default' => true ], 'usePHPPreProcessor' => [ 'description' => 'Whether to use the PHP preprocessor to expand templates', 'boolean' => true, 'default' => true ], 'addHTMLTemplateParameters' => [ 'description' => 'Parse template parameters to HTML and add them to template data', 'boolean' => true, 'default' => false ], 'maxdepth' => [ 'description' => 'Maximum expansion depth', 'default' => 40 ], 'apiURL' => [ 'description' => 'http path to remote API, e.g. http://en.wikipedia.org/w/api.php', 'default' => null ], 'rtTestMode' => [ 'description' => 'Test in rt test mode (changes some parse & serialization strategies)', 'boolean' => true, 'default' => false ], // handled by `setColorFlags` 'color' => [ 'description' => 'Enable color output Ex: --no-color', 'default' => 'auto' ] ]; // allow overriding defaults foreach ( $defaults as $name => $default ) { if ( isset( $standardOpts[$name] ) ) { $standardOpts[$name]['default'] = $default; } } // Values in $opts take precedence return $opts + $standardOpts; } }