mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-03 00:45:41 +02:00
* Generate the usage message of each tool from its long_options
The usage messages of tile-join, tippecanoe-overzoom,
tippecanoe-json-tool, tippecanoe-decode, and tippecanoe-enumerate were
hand-written lists of options that had drifted years out of date, since
nothing tied them to the options that are really accepted. Move the
option-list printing that tippecanoe already does into a shared
print_usage(), and use it in all the tools, so that the message is
derived from the same long_options table that getopt_long() gets and
can't fall behind it again.
The tables now carry section headings, as tippecanoe's does, and the
options that were only reachable by their short names (tile-join's -O,
-b, -R, and -r among them) are listed for the first time.
Also state the non-option arguments the way each tool really treats
them: tile-join takes source tilesets unless --read-from names a file to
read them from, tippecanoe-decode takes a tileset either alone or with a
zoom/x/y, tippecanoe-json-tool reads standard input when no files are
named, and tippecanoe-overzoom's two forms are the ones its argument
parsing recognizes. tippecanoe-overzoom now reports the missing -o
instead of passing NULL to fopen(), and tippecanoe-enumerate goes
through getopt_long() so that it will pick up any options added later.
The shared getopt_string() replaces the identical loop that four of the
tools each had for building the short option string, and strip_usage_headings()
the one for dropping the headings before getopt_long() sees them.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016frkRY1xXtiWjxYuCJ8vZY
* Print the usage message when tippecanoe is run with no arguments
Running `tippecanoe` with nothing at all reported the missing output
file, which is true but is not what someone who typed the bare command
needs to know. Check for the empty command line before parsing and print
the general usage message instead, and leave the specific complaint for
the case where an input file was named but an output file wasn't.
To make the message reachable from there, the options table and the
usage printing move out of main() into a usage() function, as in the
other tools.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016frkRY1xXtiWjxYuCJ8vZY
* Address review: alternation, the dead tile-join option, and --version
Four fixes from review of the generated usage messages:
* `--output` and `--output-to-directory` are one-of, not one required and
one optional, in both tippecanoe and tile-join. A `usage_required_option`
can now name an alternation that it belongs to, and the options in one
are listed together as `(--output=... | --output-to-directory=...)`,
which is what the runtime check enforces.
* tile-join's `--use-attribute-for-id` has had no implementation since
533e000 removed it; only the table entry was left behind, so the option
parsed and then exited with "Unrecognized option". Generating the usage
message from the table turned that into a documented option that doesn't
work, so remove the leftover entry too.
* `--version` was grouped under "Progress indicator", in the options table
and in the README both. Give it a heading of its own now that the
headings are something users see.
* print_usage() left `width` holding the length of the last synopsis line,
and only got away with it because every table so far begins with a
heading, which resets it. Start the option list on a line of its own
instead of depending on that.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016frkRY1xXtiWjxYuCJ8vZY
---------
Co-authored-by: Claude <noreply@anthropic.com>
92 lines
2.1 KiB
C++
92 lines
2.1 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <getopt.h>
|
|
#include <string>
|
|
#include <sqlite3.h>
|
|
#include "errors.hpp"
|
|
#include "usage.hpp"
|
|
|
|
void enumerate(char *fname) {
|
|
sqlite3 *db;
|
|
|
|
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
|
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
|
exit(EXIT_OPEN);
|
|
}
|
|
|
|
char *err = NULL;
|
|
if (sqlite3_exec(db, "PRAGMA integrity_check;", NULL, NULL, &err) != SQLITE_OK) {
|
|
fprintf(stderr, "%s: integrity_check: %s\n", fname, err);
|
|
exit(EXIT_SQLITE);
|
|
}
|
|
|
|
const char *sql = "SELECT zoom_level, tile_column, tile_row from tiles order by zoom_level, tile_column, tile_row;";
|
|
|
|
sqlite3_stmt *stmt;
|
|
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
|
|
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
|
exit(EXIT_SQLITE);
|
|
}
|
|
|
|
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
|
long long zoom = sqlite3_column_int(stmt, 0);
|
|
long long x = sqlite3_column_int(stmt, 1);
|
|
long long y = sqlite3_column_int(stmt, 2);
|
|
|
|
if (zoom < 0 || zoom > 31) {
|
|
fprintf(stderr, "Corrupt mbtiles file: impossible zoom level %lld\n", zoom);
|
|
exit(EXIT_IMPOSSIBLE);
|
|
}
|
|
|
|
y = (1LL << zoom) - 1 - y;
|
|
printf("%s %lld %lld %lld\n", fname, zoom, x, y);
|
|
}
|
|
|
|
sqlite3_finalize(stmt);
|
|
|
|
if (sqlite3_close(db) != SQLITE_OK) {
|
|
fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db));
|
|
exit(EXIT_CLOSE);
|
|
}
|
|
}
|
|
|
|
// there are no options, but the table is still what the usage message
|
|
// and the getopt string are derived from, so that they will keep up
|
|
// with any options that are added later
|
|
static const struct option long_options[] = {
|
|
{0, 0, 0, 0},
|
|
};
|
|
|
|
void usage(char **argv) {
|
|
static const char *const forms[] = {
|
|
"file.mbtiles ...",
|
|
NULL,
|
|
};
|
|
|
|
print_usage(stderr, argv[0], forms, long_options, NULL);
|
|
exit(EXIT_ARGS);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
extern int optind;
|
|
// extern char *optarg;
|
|
int i;
|
|
|
|
std::string getopt_str = getopt_string(long_options);
|
|
|
|
while ((i = getopt_long(argc, argv, getopt_str.c_str(), long_options, NULL)) != -1) {
|
|
usage(argv);
|
|
}
|
|
|
|
if (optind >= argc) {
|
|
usage(argv);
|
|
}
|
|
|
|
for (i = optind; i < argc; i++) {
|
|
enumerate(argv[i]);
|
|
}
|
|
|
|
return 0;
|
|
}
|