Parse given options and arguments to the CLI script.

@param  boolean $bool_display_help Display or not help message if no options
@access public
@return Options
165886
public function parse($bool_display_help = true)
    {
        self::addGroup('helpversion');

        // On ajoute les options spéciales Help et Version
        self::$arr_group['helpversion']->args['help'] = OptionItem::createSwitch('help')
            ->short('h')
            ->long('help')
            ->help('Display this help message and exit')
        ;


        if ($this->hasVersion()) {
            self::$arr_group['helpversion']->args['version'] = OptionItem::createSwitch('version')
                ->long('version')
                ->help('Display version information and exit')
                ;
        }

        if ($this->obj_color->opt) {
            self::$arr_group['helpversion']->args['help']->color($this->obj_color->opt);
            self::$arr_group['helpversion']->args['version']->color($this->obj_color->opt);
        }

        if ($this->obj_color->bold) {
            self::$arr_group['helpversion']->args['help']->bold();
            self::$arr_group['helpversion']->args['version']->bold();
        }

        $this->arr_parsed = getopt(
            $this->getShort(),
            $this->getLong()
        );


        $arr_argv = $_SERVER['argv'];
        array_shift($arr_argv);

        foreach ($arr_argv as $k => $v) {
            if (preg_match('/^-{1,2}/', $v)) {
                $bool_equal = (boolean) preg_match('/^[a-zA-Z0-9-]+=/', $v);

                $v = preg_replace('/(^[a-zA-Z0-9-]+)=.*/', '\1', $v);

                $opt_name = preg_replace('/^[-]+/', '', $v);

                if (array_key_exists($opt_name, $this->arr_parsed)) {
                    if (is_bool($this->arr_parsed[$opt_name])) {
                        unset($arr_argv[$k]);
                    } else {
                        unset($arr_argv[$k]);

                        if (!$bool_equal) {
                            unset($arr_argv[$k + 1]);
                        }
                    }
                }
            }
        }

        $this->arr_argument = array_values($arr_argv);


        // Checks invalid options
        $invalid_opt = null;

        foreach ($arr_argv as $v) {
            if (preg_match('/^-{1,2}/', $v)) {
                $invalid_opt = $v;
                break;
            }
        }

        if (!is_null($invalid_opt)) {
            fwrite(STDERR, sprintf('The given "%s" option is not valid!', $invalid_opt));
            fwrite(STDERR, "\n");
            exit(1);
        }



        $this->displayVersion();

        if ($this->has('help')) {
            $this->displayHelp();
        }

        if (count($this->arr_parsed) == 0 && $bool_display_help) {
            $this->displayHelp();
        }

        return $this;
    }
329518
public function optionHelp()
    {
        // Show Usage
        output()->write(
            (new Format())
                ->setContextualClass(Format::INFO)
                ->setString(language()->getLine('CLI_USAGE') . ':')
                ->setNewLinesBefore(1)
                ->setNewLinesAfter(1)
        );

        output()->write(
            (new Format())
                ->setContextualClass(Format::INFO)
                ->setString('command:action --option=value')
                ->setNewLinesAfter(2)
        );

        // Show Commanders
        $this->loadCommanders();

        if (count($this->commandersPool)) {
            output()->write(
                (new Format())
                    ->setString(language()->getLine('CLI_COMMANDS') . ':')
                    ->setNewLinesAfter(1)
            );

            $table = new Table();
            $table->isShowBorder = false;

            foreach ($this->commandersPool as $commander) {

                if ($commander instanceof AbstractCommander) {
                    $table
                        ->addRow()
                        ->addColumn($commander->getCommandName())
                        ->addColumn(language()->getLine($commander->getCommandDescription()));
                }
            }

            output()->write(
                (new Format())
                    ->setString($table->render())
                    ->setNewLinesAfter(2)
            );
        }

        // Show Options
        output()->write(
            (new Format())
                ->setString(language()->getLine('CLI_OPTIONS') . ':')
                ->setNewLinesAfter(1)
        );

        $table = new Table();
        $table->isShowBorder = false;

        $table
            ->addRow()
            ->addColumn('--version')
            ->addColumn('-v')
            ->addColumn(language()->getLine('CLI_HELP_SHOW_OPTION_VERSION'))
            ->addRow()
            ->addColumn('--help')
            ->addColumn('-h')
            ->addColumn(language()->getLine('CLI_HELP_SHOW_OPTION_HELP'))
            ->addRow()
            ->addColumn('--verbose')
            ->addColumn('-vv')
            ->addColumn(language()->getLine('CLI_HELP_SHOW_OPTION_VERBOSE'));

        output()->write(
            (new Format())
                ->setString($table->render())
                ->setNewLinesAfter(2)
        );

        exit(EXIT_SUCCESS);
    }
125019
protected static function showHelp()
    {
        \cli\line();
        \cli\out(self::$arguments->getHelpScreen(\cli\Colors::colorize('%N%n%gAvailable commands:')));
        \cli\line();
    }
470972
def parse_bool(val):
    
    true_vals = ('t', 'true', 'yes', 'y', '1', 'on')
    false_vals = ('f', 'false', 'no', 'n', '0', 'off')

    val = val.lower()
    if val in true_vals:
        return True
    if val in false_vals:
        return False

    raise ValueError('"%s" is not a valid bool value' % val)
219994
public function getOptionParser()
    {
        $parser = parent::getOptionParser();
        $parser->setDescription(
            'CakePHP Language String Extraction:'
        )->addOption('app', [
            'help' => 'Directory where your application is located.'
        ])->addOption('paths', [
            'help' => 'Comma separated list of paths.'
        ])->addOption('merge', [
            'help' => 'Merge all domain strings into the default.po file.',
            'choices' => ['yes', 'no']
        ])->addOption('relative-paths', [
            'help' => 'Use relative paths in the .pot file',
            'boolean' => true,
            'default' => false,
        ])->addOption('output', [
            'help' => 'Full path to output directory.'
        ])->addOption('files', [
            'help' => 'Comma separated list of files.'
        ])->addOption('exclude-plugins', [
            'boolean' => true,
            'default' => true,
            'help' => 'Ignores all files in plugins if this command is run inside from the same app directory.'
        ])->addOption('plugin', [
            'help' => 'Extracts tokens only from the plugin specified and puts the result in the plugin\'s Locale directory.'
        ])->addOption('ignore-model-validation', [
            'boolean' => true,
            'default' => false,
            'help' => 'Ignores validation messages in the $validate property.' .
                ' If this flag is not set and the command is run from the same app directory,' .
                ' all messages in model validation rules will be extracted as tokens.'
        ])->addOption('validation-domain', [
            'help' => 'If set to a value, the localization domain to be used for model validation messages.'
        ])->addOption('exclude', [
            'help' => 'Comma separated list of directories to exclude.' .
                ' Any path containing a path segment with the provided values will be skipped. E.g. test,vendors'
        ])->addOption('overwrite', [
            'boolean' => true,
            'default' => false,
            'help' => 'Always overwrite existing .pot files.'
        ])->addOption('extract-core', [
            'help' => 'Extract messages from the CakePHP core libs.',
            'choices' => ['yes', 'no']
        ])->addOption('no-location', [
            'boolean' => true,
            'default' => false,
            'help' => 'Do not write file locations for each extracted message.',
        ])->addOption('marker-error', [
            'boolean' => true,
            'default' => false,
            'help' => 'Do not display marker error.',
        ]);

        return $parser;
    }
925815
public function useCurrent($bool = null)
    {
        if (isset($bool)) {

            $this->option_use_current = is_bool($bool) ? $bool : false;
            $this->set_options['use_current'] = 'useCurrent';

            return $this;
        }
        else {

            return $this->option_show_today;
        }
    }
247454
public function parseBool($module, $param, $default = null)
    {
        return $this->parseSomething(
            $module,
            $param,
            $default,
            array($this, 'parseBoolHelper'),
            __FUNCTION__,
            'is_bool'
        );
    }
404209
def parse_cli_args():
    """"""
    parser = argparse.ArgumentParser(description='2048 in your terminal')
    parser.add_argument('--mode', dest='mode', type=str,
                        default=None, help='colors mode (dark or light)')
    parser.add_argument('--az', dest='azmode', action='store_true',
                        help='Use the letters a-z instead of numbers')
    parser.add_argument('--resume', dest='resume', action='store_true',
                        help='restart the game from where you left')
    parser.add_argument('-v', '--version', action='store_true')
    parser.add_argument('-r', '--rules', action='store_true')
    return vars(parser.parse_args())
994736
def parse_cli_options!(args)
      unknown_opts = []

      parser = build_cli_parser

      begin
        parser.parse!(args)
      rescue OptionParser::InvalidOption => e
        unknown_opts << e.args[0]
        unless args.size.zero?
          unknown_opts << args.shift unless args.first.start_with?("-")
          retry
        end
      end

      unknown_opts
    end
1123122
public function showCommandList(bool $showLogo = true)
    {
        $commands = $this->parserCmdAndDesc();

        $commandList = [];
        $script = \input()->getFullScript();
        $commandList['Usage:'] = ["php $script {command} [arguments] [options]"];
        $commandList['Commands:'] = $commands;
        $commandList['Options:'] = [
            '-h, --help'    => 'Display help information',
            '-v, --version' => 'Display version information',
        ];

        // show logo
        if ($showLogo) {
            \output()->writeLogo();
        }

        // output list
        \output()->writeList($commandList, 'comment', 'info');
    }
111718
protected function parseCommandAndConfig()
    {
        $this->parseCliOptions();

        $command = $this->command;
        $supported = ['start', 'stop', 'restart', 'reload', 'status'];

        if (!\in_array($command, $supported, true)) {
            $this->showHelp("The command [{$command}] is don't supported!");
        }

        // load CLI Options
        $this->loadCliOptions($this->cliOpts);

        // init Config And Properties
        $this->initConfigAndProperties($this->config);

        // Debug option to dump the config and exit
        if (isset($this->cliOpts['D'])) {
            $val = $this->cliOpts['D'];
            $this->dumpInfo($val === 'all');
        } elseif (isset($this->cliOpts['dump'])) {
            $val = $this->cliOpts['dump'];
            $this->dumpInfo($val === 'all');
        }
    }
1325741
def parse_command_line(args: List[str] = None, final: bool = True) -> List[str]:
    
    return options.parse_command_line(args, final=final)
63531
protected function parseArguments() {
        $this->config['arguments'] = [];

        $commandFound =false;

        for ($index = 0; $index < count($this->config['args']); $index++) {
            // Ignore binary name:
            if ($index === 0) {
                continue;
            }

            $arg = $this->config['args'][$index];

            // Ignore command:
            if (array_key_exists($arg, $this->config['commands']) &&
                $commandFound === false) {
                $commandFound = true;
                continue;
            }

            // Ignore options:
            if (strpos($arg, '--') === 0) {
                foreach ($this->options as $option) {
                    if (!array_key_exists('long', $option)) {
                        continue;
                    }

                    if ('--' . $option['long'] !== $arg) {
                        continue;
                    }

                    if ($option['value'] !== self::NO_VALUE &&
                        strpos($arg, '--' . $option['long'] . '=') === 0) {
                        break;
                    } elseif ($option['value'] === self::NO_VALUE) {
                        $index += 1;
                        break;
                    } else {
                        $index += 2;
                        break;
                    }
                }
            } elseif (strpos($arg, '-') === 0) {
                foreach ($this->options as $option) {
                    if (!array_key_exists('short', $option)) {
                        continue;
                    }

                    if ('-' . $option['short'] !== $arg) {
                        continue;
                    }

                    if ($option['value'] === self::NO_VALUE) {
                        $index += 1;
                        break;
                    } else {
                        $index += 2;
                        break;
                    }
                }
            } else {
                $this->config['arguments'][] = $arg;
            }
        }

        return $this;
    }
1328241
public function parse(): bool
    {
        if ($this->valid === true) {
            /**
             * Before processing through the deltas, generate new deltas by splliting
             * on all new lines, will make it much simpler to work out which
             * delta belong to headings, lists etc.
             */
            $this->quill_json = $this->splitInsertsByNewline($this->quill_json['ops']);

            foreach ($this->quill_json as $quill) {

                if ($quill['insert'] !== null) {
                    if (
                        array_key_exists('attributes', $quill) === true &&
                        is_array($quill['attributes']) === true
                    ) {
                        if (count($quill['attributes']) === 1) {
                            foreach ($quill['attributes'] as $attribute => $value) {
                                switch ($attribute) {
                                    case Options::ATTRIBUTE_BOLD:
                                        $this->attributeBold($quill);
                                        break;

                                    case Options::ATTRIBUTE_COLOR:
                                        $this->attributeColor($quill);
                                        break;

                                    case Options::ATTRIBUTE_HEADER:
                                        $this->attributeHeader($quill);
                                        break;

                                    case Options::ATTRIBUTE_ITALIC:
                                        $this->attributeItalic($quill);
                                        break;

                                    case Options::ATTRIBUTE_LINK:
                                        $this->attributeLink($quill);
                                        break;

                                    case Options::ATTRIBUTE_LIST:
                                        $this->attributeList($quill);
                                        break;

                                    case Options::ATTRIBUTE_SCRIPT:
                                        $this->attributeScript($quill);
                                        break;

                                    case Options::ATTRIBUTE_STRIKE:
                                        $this->attributeStrike($quill);
                                        break;

                                    case Options::ATTRIBUTE_UNDERLINE:
                                        $this->attributeUnderline($quill);
                                        break;

                                    default:
                                        $this->insert($quill);
                                        break;
                                }
                            }
                        } else {
                            $this->compoundInsert($quill);
                        }
                    } else {
                        if (is_string($quill['insert']) === true) {
                            $this->insert($quill);
                        } else {
                            if (is_array($quill['insert']) === true) {
                                if (array_key_exists('image', $quill['insert']) === true) {
                                    $this->image($quill);
                                } else if (array_key_exists('video', $quill['insert']) === true) {
                                    $this->video($quill);
                                }
                            }
                        }
                    }
                }
            }
            return true;
        } else {
            return false;
        }
    }
791047
public function getOptionParser()
    {
        $parser = parent::getOptionParser();

        $parser->addOption('cli', [
                'help' => 'Use the bootstrap_cli file.',
                'boolean' => true,
                'default' => false,
            ])
            ->addOption('no_app', [
                'help' => 'Do not update the Application if it exist. Forces config/bootstrap.php to be updated.',
                'boolean' => true,
                'default' => false,
            ])
            ->addArgument('plugin', [
                'help' => 'Name of the plugin to load.',
            ]);

        return $parser;
    }
1013538
public function getHelp()
    {
        print Color::head('Help:') . PHP_EOL;
        print Color::colorize('  Lists the commands available in Console') . PHP_EOL . PHP_EOL;

        $this->run([]);
    }
554219
protected function _parseOptions($options)
    {
        if (!empty($options['label']) && $options['label']) {
            if (!is_array($options['label'])) {
                $options['label'] = ['text' => $options['label']];
            }
            $options['label'] = array_merge_recursive($options['label'], ['class' => 'control-label']);
        }
        return parent::_parseOptions($options);
    }