Skip to content

Commit

Permalink
feat: add help argument to output cli options
Browse files Browse the repository at this point in the history
  • Loading branch information
eknowles committed Aug 19, 2024
1 parent 2a9ad12 commit 9f37486
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
46 changes: 14 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,38 +80,20 @@ tilepack -i <input_url> [options]

## Options

- `-i, --input <input_url>` (required):
The base URL for the XYZ tiles.

- `-o, --output <output_file>` (default: `output.mbtiles`):
The path where the MBTiles file will be saved.

- `--minzoom <min_zoom>`:
The minimum zoom level to fetch tiles.

- `--maxzoom <max_zoom>`:
The maximum zoom level to fetch tiles.

- `--bbox <bounding_box>`:
The bounding box for the tile fetching in the
format `minLon,minLat,maxLon,maxLat`.

- `--header <header>` (can be used multiple times):
HTTP headers to include in tile requests. Use this option for each header.

- `--token <api_token>`:
An API token for authenticated requests. Used in `input` URL.

- `--retry <retry_count>` (default: `0`):
The number of retry attempts for failed requests.

- `--format <image_format>` (default: `png`):
The format of the tiles (e.g., `png`, `jpeg`).

- `--concurrency <concurrent_requests>` (default: `15`):
The number of concurrent requests to fetch tiles.

## Example
| Option | Description | Default |
|--------|-------------|---------|
| `-i, --input <input_url>` | The base URL for the XYZ tiles (required) | N/A |
| `-o, --output <output_file>` | The path where the MBTiles file will be saved | `output.mbtiles` |
| `--minzoom <min_zoom>` | The minimum zoom level to fetch tiles | N/A |
| `--maxzoom <max_zoom>` | The maximum zoom level to fetch tiles | N/A |
| `--bbox <bounding_box>` | The bounding box for the tile fetching in the format `minLon,minLat,maxLon,maxLat` | N/A |
| `--header <header>` | HTTP headers to include in tile requests. Use this option for each header | N/A |
| `--token <api_token>` | An API token for authenticated requests. Used in `input` URL | N/A |
| `--retry <retry_count>` | The number of retry attempts for failed requests | `0` |
| `--format <image_format>` | The format of the tiles (e.g., `png`, `jpeg`) | `png` |
| `--concurrency <concurrent_requests>` | 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

Expand Down
24 changes: 24 additions & 0 deletions src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { parseArgs } from "util";

export interface CliArgs {
version: boolean;
help: boolean;
output: string;
input: string;
minzoom: number;
Expand All @@ -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" },
Expand All @@ -34,8 +36,30 @@ export function parseCliArgs(): CliArgs {
allowPositionals: false,
});

if (values.help) {
console.log(`
Usage: tilepack -i <input_url> [options]
Options:
-i, --input <input_url> The base URL for the XYZ tiles (required)
-o, --output <output_file> The path where the MBTiles file will be saved (default: output.mbtiles)
--minzoom <min_zoom> The minimum zoom level to fetch tiles
--maxzoom <max_zoom> The maximum zoom level to fetch tiles
--bbox <bounding_box> The bounding box for the tile fetching in the format minLon,minLat,maxLon,maxLat
--header <header> HTTP headers to include in tile requests. Use this option for each header
--token <api_token> An API token for authenticated requests. Used in input URL
--retry <retry_count> The number of retry attempts for failed requests (default: 0)
--format <image_format> The format of the tiles (e.g., png, jpeg) (default: png)
--concurrency <concurrent_requests> 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),
Expand Down

0 comments on commit 9f37486

Please sign in to comment.