Add CLI dispatcher and bin entry
Top-level run(argv,{out,err}) accepts an injectable output sink so
handlers can be unit-tested without spawning a subprocess. Handler
map is empty for now; subcommands are wired in as they land.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
43
src/cli.js
Normal file
43
src/cli.js
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const USAGE = `usage: sporel-mapper <subcommand> [args...]
|
||||
|
||||
Subcommands:
|
||||
encode <atlas_idx> <tile_id> [rotation]
|
||||
Print the packed-u32 GID for the given components.
|
||||
|
||||
decode <gid>
|
||||
Print the (atlas, tile, rotation) components of a GID.
|
||||
|
||||
build <spec.txt> <out.json> [--atlas-dir <path> ...]
|
||||
Compile a text-DSL map spec into a v2 map JSON file.
|
||||
|
||||
inspect <map.json> [--atlas-dir <path> ...]
|
||||
Print a human-readable stats report for a v2 map.
|
||||
|
||||
Options:
|
||||
-h, --help Show this message.
|
||||
`;
|
||||
|
||||
function run(argv, { out, err }) {
|
||||
if (argv.length === 0) {
|
||||
err.write(USAGE);
|
||||
return 1;
|
||||
}
|
||||
const [head, ...rest] = argv;
|
||||
if (head === '-h' || head === '--help') {
|
||||
out.write(USAGE);
|
||||
return 0;
|
||||
}
|
||||
const handlers = {
|
||||
// populated in subsequent tasks
|
||||
};
|
||||
const handler = handlers[head];
|
||||
if (!handler) {
|
||||
err.write(`unknown subcommand: ${head}\n${USAGE}`);
|
||||
return 1;
|
||||
}
|
||||
return handler.run(rest, { out, err });
|
||||
}
|
||||
|
||||
module.exports = { run };
|
||||
Reference in New Issue
Block a user