From 9f374865973e9d1e490c9b87030902c503b61cce Mon Sep 17 00:00:00 2001 From: Edward Knowles <817611+eknowles@users.noreply.github.com> Date: Mon, 19 Aug 2024 07:51:46 +0100 Subject: [PATCH] feat: add `help` argument to output cli options --- README.md | 46 ++++++++++++++-------------------------------- src/args.ts | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index e18e73d..3457525 100644 --- a/README.md +++ b/README.md @@ -80,38 +80,20 @@ tilepack -i [options] ## Options -- `-i, --input ` (required): - The base URL for the XYZ tiles. - -- `-o, --output ` (default: `output.mbtiles`): - The path where the MBTiles file will be saved. - -- `--minzoom `: - The minimum zoom level to fetch tiles. - -- `--maxzoom `: - The maximum zoom level to fetch tiles. - -- `--bbox `: - The bounding box for the tile fetching in the - format `minLon,minLat,maxLon,maxLat`. - -- `--header
` (can be used multiple times): - HTTP headers to include in tile requests. Use this option for each header. - -- `--token `: - An API token for authenticated requests. Used in `input` URL. - -- `--retry ` (default: `0`): - The number of retry attempts for failed requests. - -- `--format ` (default: `png`): - The format of the tiles (e.g., `png`, `jpeg`). - -- `--concurrency ` (default: `15`): - The number of concurrent requests to fetch tiles. - -## Example +| Option | Description | Default | +|--------|-------------|---------| +| `-i, --input ` | The base URL for the XYZ tiles (required) | N/A | +| `-o, --output ` | The path where the MBTiles file will be saved | `output.mbtiles` | +| `--minzoom ` | The minimum zoom level to fetch tiles | N/A | +| `--maxzoom ` | The maximum zoom level to fetch tiles | N/A | +| `--bbox ` | The bounding box for the tile fetching in the format `minLon,minLat,maxLon,maxLat` | N/A | +| `--header
` | HTTP headers to include in tile requests. Use this option for each header | N/A | +| `--token ` | An API token for authenticated requests. Used in `input` URL | N/A | +| `--retry ` | The number of retry attempts for failed requests | `0` | +| `--format ` | The format of the tiles (e.g., `png`, `jpeg`) | `png` | +| `--concurrency ` | The number of concurrent requests to fetch tiles | `15` | +| `-v, --version` | Show the version number | N/A | +| `-h, --help` | Show this help message | N/A | Bounding box can be created using https://norbertrenner.de/osm/bbox.html diff --git a/src/args.ts b/src/args.ts index cd1e12e..6c9fa2f 100644 --- a/src/args.ts +++ b/src/args.ts @@ -2,6 +2,7 @@ import { parseArgs } from "util"; export interface CliArgs { version: boolean; + help: boolean; output: string; input: string; minzoom: number; @@ -19,6 +20,7 @@ export function parseCliArgs(): CliArgs { args: Bun.argv.slice(2), options: { version: { type: "boolean", short: "v" }, + help: { type: "boolean", short: "h" }, output: { type: "string", short: "o", default: "output.mbtiles" }, input: { type: "string", short: "i" }, minzoom: { type: "string" }, @@ -34,8 +36,30 @@ export function parseCliArgs(): CliArgs { allowPositionals: false, }); + if (values.help) { + console.log(` +Usage: tilepack -i [options] + +Options: + -i, --input The base URL for the XYZ tiles (required) + -o, --output The path where the MBTiles file will be saved (default: output.mbtiles) + --minzoom The minimum zoom level to fetch tiles + --maxzoom The maximum zoom level to fetch tiles + --bbox The bounding box for the tile fetching in the format minLon,minLat,maxLon,maxLat + --header
HTTP headers to include in tile requests. Use this option for each header + --token An API token for authenticated requests. Used in input URL + --retry The number of retry attempts for failed requests (default: 0) + --format The format of the tiles (e.g., png, jpeg) (default: png) + --concurrency The number of concurrent requests to fetch tiles (default: 15) + -v, --version Show the version number + -h, --help Show this help message + `); + process.exit(0); + } + return { version: values.version as boolean, + help: values.help as boolean, output: values.output as string, input: values.input as string, minzoom: parseInt(values.minzoom as string),