Bug ou pas bug sur module PEAR : Console_Getopt
Bonjour,
Je suis entrain d'ecrire un script PHP dans lequel j'utilise le module PEAR Console_Getopt pour parser ma ligne de commande.
Je suis tombé sur ce qui ressemble a un bug :
Si je fait cette commande :
Code:
generer_comptes.php --file='liste.csv tain.zeb' -f='toto.txt béurk.csv'
mon tableau d'argument retourné par Console_Getopt est le suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
Array
(
[0] => Array
(
[0] => Array
(
[0] => --file
[1] => liste.csv tain.zeb
)
[1] => Array
(
[0] => f
[1] => =toto.txt béurk.csv
)
)
[1] => Array
(
)
) |
il me met un = devant le nom de fichier toto .... :-(
Voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
$shortopts = "";
$shortopts .= "f:"; // Valeur requise
$shortopts .= "d::"; // Valeur optionnelle
$shortopts .= "h";
$longopts = array(
"file=",
"user=", // requis
"delimiter==", // Valeur optionnelle
"help"
);
// Get an instance of new Console_Getopt -> module de php-pear
require_once 'Console/Getopt.php';
$getopt = new Console_Getopt();
// Get the arguments & remove the filename from the list
$args = $getopt->readPHPArgv();
array_shift($args);
$options = $getopt->getopt( $args, $shortopts, $longopts );
print_r( $options );
if ( PEAR::isError( $options ) )
{
echo 'Got error: ' . $options->getMessage() . PHP_EOL;
show_help();
exit(0);
}
?>
<?php |