New package `BoostlikeGetopt\'
| From: | Yokoyama, Shinobu | Date: | Mon, 08 Mar 2010 04:35:36 +0000 |
| Subject: | New package `BoostlikeGetopt\' | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-53299@lists.php.net to get a copy of this message | ||
Although this is only a trivial Getopt package modification, I suppose the
implementation helps quite a few of new Getopt users.
Thanks to Andrei Zmievski (author of this package), here I want to request
yet-another package named `BoostlikeGetopt\' ( or can be patch ? ).
Additional methods:
bool count(KEYNAME) : like boost `program_options\', only reports if
option specified.
mix operator [] : corresponding regular
get\' and set\' method.
Additional members:
$options : option values (former $getopt_args[0])
$args : alias to non-option (former $getopt_args[1])
Download source code:
http://project.yolcoyama.net/open/php/BoostlikeGetopt.php
Demo:
To boost user, or even non-boost user who is new to Getopt, following
code may illustrate how `boost-like\' superiors to array based access to
options.
-------- code[BEGIN] -----------
require_once(\"Console/BoostlikeGetopt.php\");
$opt = new Console_Getopt;
$opt->getopt($opt->readPHPArgv(), \"hm:\", array(\"help\"));
if(@PEAR::isError($opt)){
fprintf(STDERR, $opt->getMessage());
exit(1);
}
echo \"`h\' option:\\n\"; var_dump($opt->count(\"h\"),
$opt[\"h\"]);
echo \"\\n`m\' option:\\n\"; var_dump($opt->count(\"m\"),
$opt[\"m\"]);
$opt[\"m\"] = 64;
echo \"\\nmodified `m\' option:\\n\"; var_dump($opt->count(\"m\"),
$opt[\"m\"]);
/* output: */
/* $ ./demo.php -m 32 -h */
/* `h\' option: */
/* bool(true) */
/* NULL */
/* `m\' option: */
/* bool(true) */
/* string(2) \"32\" */
/* modified `m\' option: */
/* bool(true) */
/* int(64) */
-------- code[END] -----------
Thank you.