function main()
{
    global $quiet;
    $options = BoostSiteTools\CommandLineOptions::parse(UPDATE_DOC_LIST_USAGE, array('quiet' => false));
    $quiet = $options->flags['quiet'];
    $location = null;
    $version = null;
    switch (count($options->positional)) {
        case 2:
            $version = $options->positional[1];
        case 1:
            $location = $options->positional[0];
        case 0:
            break;
        default:
            echo $options->usage_message();
            exit(1);
    }
    if ($version) {
        // BoostVersion dies if version is invalid.
        $version = BoostVersion::from($version);
    }
    $libs = BoostLibraries::from_xml_file(dirname(__FILE__) . '/../doc/libraries.xml');
    $updates = array();
    if ($location) {
        $real_location = realpath($location);
        if ($real_location && !is_dir($real_location)) {
            echo "Not a directory: {$location}\n";
            exit(1);
        }
        $location = $real_location;
        // If this is not a git repo.
        // TODO: Don't output stderr.
        exec("cd \"{$location}\" && git rev-parse --git-dir", $output, $return_var);
        if ($return_var != 0) {
            if (!$version || !$version->is_numbered_release()) {
                echo "Error: Release version required for release.\n";
                exit(1);
            }
            $updates[(string) $version] = read_metadata_from_filesystem($location, $version);
        } else {
            if (get_bool_from_array(BoostSuperProject::run_process("cd '{$location}' && git rev-parse --is-bare-repository"))) {
                if ($version) {
                    $updates[(string) $version] = read_metadata_from_git($location, $version);
                } else {
                    $updates[(string) 'master'] = read_metadata_from_git($location, 'master');
                    $updates[(string) 'develop'] = read_metadata_from_git($location, 'develop');
                }
            } else {
                // TODO: Could get version from the branch in a git checkout.
                if (!$version) {
                    echo "Error: Version required for local tree.\n";
                    exit(1);
                }
                $updates[(string) $version] = read_metadata_from_filesystem($location, $version);
            }
        }
    }
    if ($updates) {
        foreach ($updates as $update_version => $update) {
            $libs->update($update_version, $update);
        }
    } else {
        $libs->update();
    }
    if (!$quiet) {
        echo "Writing to disk\n";
    }
    file_put_contents(dirname(__FILE__) . '/../doc/libraries.xml', $libs->to_xml());
    $libs->squash_name_arrays();
    file_put_contents(dirname(__FILE__) . '/../generated/libraries.txt', serialize($libs));
}
function main()
{
    $args = $_SERVER['argv'];
    $location = null;
    $version = null;
    switch (count($args)) {
        case 3:
            $version = $args[2];
        case 2:
            $location = $args[1];
        case 1:
            break;
        default:
            echo "Usage: update-doc-list.php [path] [version]\n";
            exit(1);
    }
    if ($version) {
        // BoostVersion dies if version is invalid.
        $version = BoostVersion::from($version);
    }
    $libs = BoostLibraries::from_xml_file(dirname(__FILE__) . '/../doc/libraries.xml');
    $updates = array();
    if ($location) {
        $real_location = realpath($location);
        if ($real_location && !is_dir($real_location)) {
            echo "Not a directory: {$location}\n";
            exit(1);
        }
        $location = $real_location;
        // If this is not a git repo.
        // TODO: Don't output stderr.
        exec("cd \"{$location}\" && git rev-parse --git-dir", $output, $return_var);
        if ($return_var != 0) {
            if (!$version || !$version->is_numbered_release()) {
                echo "Error: Release version required for release.\n";
                exit(1);
            }
            $updates[(string) $version] = read_metadata_from_release($location, $version, $libs);
        } else {
            if (get_bool_from_array(BoostSuperProject::run_process("cd '{$location}' && git rev-parse --is-bare-repository"))) {
                if ($version) {
                    $updates[(string) $version] = read_metadata_from_git($location, $version);
                } else {
                    $updates[(string) 'master'] = read_metadata_from_git($location, 'master');
                    $updates[(string) 'develop'] = read_metadata_from_git($location, 'develop');
                }
            } else {
                // TODO: Could get version from the branch in a git checkout.
                if (!$version) {
                    echo "Error: Version required for local tree.\n";
                    exit(1);
                }
                $updates[(string) $version] = read_metadata_from_local_clone($location, $version);
            }
        }
    }
    if ($updates) {
        foreach ($updates as $update_version => $update) {
            $libs->update($update_version, $update);
        }
    } else {
        $libs->update();
    }
    echo "Writing to disk\n";
    file_put_contents(dirname(__FILE__) . '/../doc/libraries.xml', $libs->to_xml());
    $libs->squash_name_arrays();
    file_put_contents(dirname(__FILE__) . '/../generated/libraries.txt', serialize($libs));
}