2019-05-20 11:18:25 +00:00
|
|
|
#!/usr/bin/env node
|
2019-05-20 16:06:20 +00:00
|
|
|
"use strict";
|
2019-05-20 11:18:25 +00:00
|
|
|
|
2019-05-23 19:10:06 +00:00
|
|
|
// 1: Setup & Imports
|
2019-05-20 13:38:20 +00:00
|
|
|
import ansi from './Helpers/Ansi.mjs';
|
2019-05-23 19:10:06 +00:00
|
|
|
import c from './bootstrap/container.mjs';
|
2019-05-20 11:18:25 +00:00
|
|
|
|
|
|
|
import show_help from './help.mjs';
|
|
|
|
import TTNAppServer from './ttn-app-server/TTNAppServer.mjs';
|
2019-05-23 19:10:06 +00:00
|
|
|
import settings from './bootstrap/settings.mjs';
|
2019-05-20 11:18:25 +00:00
|
|
|
|
|
|
|
// 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(`${ansi.fred}${ansi.hicol}Error: No subcommand specified.${ansi.reset}`);
|
|
|
|
show_help(settings);
|
|
|
|
process.exit();
|
|
|
|
}
|
2019-05-20 13:38:20 +00:00
|
|
|
|
2019-05-20 11:18:25 +00:00
|
|
|
switch(extras[0]) {
|
|
|
|
case "ttn-app-server":
|
|
|
|
let app_server = new TTNAppServer(settings);
|
|
|
|
app_server.run();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
console.error(`${ansi.fred}${ansi.hicol}Error: Subcommand '${extras[0]}' not recognised.${ansi.reset}`);
|
|
|
|
console.error( `${ansi.fred}Perhaps you mistyped it, or it hasn't been implemented yet?`);
|
|
|
|
process.exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5: Cleanup
|