예제 #1
0
function usage($error = null, $helpsubject = null)
{
    global $progname, $all_commands;
    $stderr = fopen('php://stderr', 'w');
    if (PEAR::isError($error)) {
        fputs($stderr, $error->getMessage() . "\n");
    } elseif ($error !== null) {
        fputs($stderr, "{$error}\n");
    }
    if ($helpsubject != null) {
        $put = cmdHelp($helpsubject);
    } else {
        $put = "Commands:\n";
        $maxlen = max(array_map("strlen", $all_commands));
        $formatstr = "%-{$maxlen}s  %s\n";
        ksort($all_commands);
        foreach ($all_commands as $cmd => $class) {
            $put .= sprintf($formatstr, $cmd, PEAR_Command::getDescription($cmd));
        }
        $put .= "Usage: {$progname} [options] command [command-options] <parameters>\n" . "Type \"{$progname} help options\" to list all options.\n" . "Type \"{$progname} help shortcuts\" to list all command shortcuts.\n" . "Type \"{$progname} help <command>\" to get the help for the specified command.";
    }
    fputs($stderr, "{$put}\n");
    fclose($stderr);
    exit;
}