Skip to content

Instantly share code, notes, and snippets.

@henriquemoody
Created August 28, 2012 23:32
Show Gist options
  • Save henriquemoody/3505312 to your computer and use it in GitHub Desktop.
Save henriquemoody/3505312 to your computer and use it in GitHub Desktop.
#!/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