Created
August 28, 2012 23:32
-
-
Save henriquemoody/3505312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
$file = array_shift($_SERVER['argv']); | |
$help = "Utilização de {$file} [ OPTIONS ] | |
-s, --say Diz alguma coisa | |
-t, --to Diz pra quem quer dizer alguma coisa | |
"; | |
if (empty($_SERVER['argv'])) { | |
fwrite(STDERR, $help . "\n"); | |
exit (1); | |
} | |
$shortopts = ""; | |
$shortopts .= "s:"; | |
$shortopts .= "t:"; | |
$longopts = array( | |
"say:", | |
"to::", | |
); | |
$options = getopt($shortopts, $longopts); | |
if (!isset($options['s'])) { | |
fwrite(STDOUT, "Preenchimento do parâmetro \"-s\" é obrigatório.\n"); | |
exit (2); | |
} | |
if (!isset($options['t'])) { | |
fwrite(STDOUT, "Para quem você quer dizer \"{$options['s']}\"?\n> "); | |
$options['t'] = trim(fgets(STDIN)); | |
if (empty($options['t'])) { | |
fwrite(STDERR, "Você precisa dizer pra quem quer dizer \"{$options['s']}\"\n"); | |
exit (3); | |
} | |
} | |
fwrite(STDOUT, "{$options['s']}, {$options['t']}!\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment