PHP library for getting command line parameters and parameters

Is there a PHP library that I can use to parse parameters and parameters in a php script command line? I know the getopt function, but is there something similar for the parameters?

+4
source share
3 answers

Use getopt for parameters and $argv array for parameters - http://php.net/manual/en/reserved.variables.argv.php

also see http://docs.php.net/manual/en/features.commandline.php for things like reading arguments from $argv form --name=VALUE

+5
source

getopt is an option, but it's not funny, especially if you're used to Python (or Ruby, which probably has nice looking argv parses). Here are some of the best alternatives; they probably all require PHP 5.3+.

  • I tried Commando and I am pleased with that.

  • ConsoleKit would be next in line.

  • php-cli-tools has some more features, such as progress indicators and table displays. I just found it 10 minutes ago, since I want a tabular display, I can at some point go to this library from Commando.

  • Also check out GetOptionKit as it can handle subcommands.

+6
source

The CLIFramework checkout processes subcommands, checking arguments, parameter values ​​(multiple, flag, optional, default) and a powerful zsh / bash completion generator.

Here is a screencast using the zsh completion generator (it completes the arguments and options):

zsh completion generator

There are also many popular applications using CLIFramework and GetOptionKit. e.g. PHPBrew , LazyRecord

+4
source

Source: https://habr.com/ru/post/1401793/


All Articles