75 lines
1.8 KiB
JavaScript
Executable file
75 lines
1.8 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
// 1: Setup & Imports
|
|
import c from './bootstrap/container.mjs';
|
|
|
|
import show_help from './help.mjs';
|
|
import { decode_payload } from './ttn-app-server/DecodePayload.mjs';
|
|
|
|
const settings = c.resolve("settings");
|
|
const a = c.resolve("ansi");
|
|
const l = c.resolve("log");
|
|
|
|
// 2: CLI Argument Parsing
|
|
let args = process.argv.slice(2); // Slice out the node binary name and the filename
|
|
let extras = [];
|
|
for(let i = 0; i < args.length; i++) {
|
|
if(!args[i].startsWith("-")) {
|
|
extras.push(args[i]);
|
|
continue;
|
|
}
|
|
|
|
switch(args[i]) {
|
|
case "--help":
|
|
case "-h":
|
|
show_help(settings);
|
|
process.exit();
|
|
break;
|
|
|
|
case "--version":
|
|
case "-v":
|
|
console.log(program.version);
|
|
break;
|
|
|
|
// Add more arguments here
|
|
}
|
|
}
|
|
|
|
// 3: Environment Variable Parsing
|
|
|
|
// process.env.XYZ
|
|
|
|
// 4: Run
|
|
if(extras.length < 1) {
|
|
console.error(`${a.fred}${a.hicol}Error: No subcommand specified.${a.reset}`);
|
|
show_help(settings);
|
|
process.exit();
|
|
}
|
|
|
|
l.log(`${a.fgreen}${a.hicol}*** LoRaWAN Signal Mapper ***${a.reset}`);
|
|
|
|
switch(extras[0]) {
|
|
case "ttn-app-server":
|
|
l.log(`${a.fgreen}${a.hicol}Starting The Things Network application server${a.reset}`);
|
|
|
|
let app_server = c.resolve("TTNAppServer");
|
|
app_server.run();
|
|
break;
|
|
|
|
case "decode-test":
|
|
l.log(`${a.fgreen}${a.hicol}Decoding message${a.reset}`);
|
|
if(process.argv.length < 4) {
|
|
l.error("No message specified. Specify the message to decode in single quotes directly after 'decode-test'.");
|
|
process.exit(1);
|
|
}
|
|
l.log("Input: ", process.argv[3]);
|
|
l.log("Output: ", decode_payload(process.argv[3]));
|
|
break;
|
|
|
|
default:
|
|
console.error(`${a.fred}${a.hicol}Error: Subcommand '${extras[0]}' not recognised.${a.reset}`);
|
|
console.error( `${a.fred}Perhaps you mistyped it, or it hasn't been implemented yet?`);
|
|
process.exit(1);
|
|
break;
|
|
}
|