From 48516a66121dea1e8d3c1174b6f46ecd71be5a92 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Tue, 7 Nov 2017 23:55:33 +0530 Subject: [PATCH] Create listFile directory if doesn't exist --- index.js | 19 +++++++++++++------ utils/listFile.js | 5 ++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index d69294e..90e5583 100755 --- a/index.js +++ b/index.js @@ -14,17 +14,19 @@ var createProxyServer = require('./actions/createProxyServer'); var createStaticServer = require('./actions/createStaticServer'); var killServer = require('./actions/killServer'); -var jsonFile; //appendToList("example.com", "80"); //appendToList("example2.com", "80", "4000"); //appendToList("example2.com", "80", "4444"); -console.log(jsonFile); // Check for requirements such as OS version and nginx install. Throw and exit if requirements not found. #Roadmap: Add ability to satisfy any possible requirements. requirements(); // Comment in development and uncomment this line in production. This should check whether the OS is compatible with this version of `up` program - .version('0.1.5'); + .version('0.1.5') + .arguments(' [options]') + .action ( function(cmd) { + var cmdValue = cmd; + }); program .command('static [outPort]') @@ -65,9 +67,9 @@ program }); program - .command('*') // This should pick invalid commands, but it doesn't, yet. + .command('*') // This picks invalid commands, but doesn't pick empty commands, yet. .action(function () { - console.log("Invalid command. Type " + chalk.cyan('up --help') + " for help."); + console.log("\n Invalid command. Type " + chalk.cyan('up --help') + " for help.\n"); }); // Adds custom help text to the automatically generated help. @@ -84,4 +86,9 @@ program.on('--help', function () { }); // Parses commands passed to `up` and chooses one of the above commands. -program.parse(process.argv); \ No newline at end of file +program.parse(process.argv); + +if (typeof cmdValue == 'undefined') { + console.log("\nNo commands given. Exiting...\n"); + process.exit(1); +} \ No newline at end of file diff --git a/utils/listFile.js b/utils/listFile.js index 4331a5e..814ec2a 100644 --- a/utils/listFile.js +++ b/utils/listFile.js @@ -4,10 +4,13 @@ var beautifyJSON = require("json-beautify"); var EOL = require('os').EOL; // \n if used on Linux, \r\n if used on Windows. -var listFilePath = "/etc/up-serve/servers.up"; +var listFileDir = "/etc/up-serve/"; +var listFilePath = listFileDir + "servers.up"; function appendToList(domain, outPort, inPort) { + shell.mkdir('-p', listFileDir); + var jsonFile = {}; var domBlock;