'use strict'; const USAGE = `usage: sporel-mapper [args...] Subcommands: encode [rotation] Print the packed-u32 GID for the given components. decode Print the (atlas, tile, rotation) components of a GID. build [--atlas-dir ...] Compile a text-DSL map spec into a v2 map JSON file. inspect [--atlas-dir ...] 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 = { encode: require('./commands/encode'), decode: require('./commands/decode'), build: require('./commands/build'), inspect: require('./commands/inspect'), }; const handler = handlers[head]; if (!handler) { err.write(`unknown subcommand: ${head}\n${USAGE}`); return 1; } return handler.run(rest, { out, err }); } module.exports = { run };