if (php_sapi_name() != 'cli')
$usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=<src_url>");
else
- $usage = "{$argv[0]} <src_url>\n";
+ $usage = "{$argv[0]} [-h|--help] <src_url>\n";
return "usage: $usage";
}
if ($argc < 2)
return $options;
- if ($argv[1] == "-h" || $argv[1] == "--help")
- echo usage($argv);
- else
- $options['src_url'] = $argv[1];
+ $cli_options = getopt("h", array("help"));
+ foreach ($cli_options as $opt => $val) {
+ switch ($opt) {
+ case 'h':
+ case 'help':
+ echo usage($argv);
+ exit(0);
+ default:
+ die(usage($argv));
+ }
+ }
+
+ $options['src_url'] = $argv[count($cli_options) + 1];
return $options;
}