Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow location of settings.json to be overridden through cli arg #455

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions bin/installDeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ if [ ! $(echo $NODE_VERSION | cut -d "." -f 1-2) = "v0.6" ]; then
exit 1
fi

#Does a settings.json exist? if no copy the template
if [ ! -f "settings.json" ]; then
echo "Copy the settings template to settings.json..."
cp -v settings.json.template settings.json || exit 1
#Get the name of the settings file
settings="settings.json"
a='';
for arg in $*; do
if [ "$a" = "--settings" ] || [ "$a" = "-s" ]; then settings=$arg; fi
a=$arg
done
#Does a $settings exist? if no copy the template
if [ ! -f $settings ]; then
echo "Copy the settings template to $settings..."
cp -v settings.json.template $settings || exit 1
fi

echo "Ensure that all dependencies are up to date..."
Expand Down
14 changes: 11 additions & 3 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ if [ "$(id -u)" -eq 0 ]; then
fi
fi

prep=1
#If merely looking for help, don't prep the environment
for arg in $*; do
if [ "$arg" = "--help" ] || [ "$arg" = "-h" ]; then prep=0; fi
done

#prepare the enviroment
bin/installDeps.sh || exit 1
if [ $prep -eq 1 ]; then
bin/installDeps.sh $* || exit 1
echo "start..."
fi

#Move to the node folder and start
echo "start..."
cd "node"
node server.js
node server.js $*
1 change: 1 addition & 0 deletions node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* limitations under the License.
*/

var cli = require('./utils/Cli');
var ERR = require("async-stacktrace");
var log4js = require('log4js');
var os = require("os");
Expand Down
53 changes: 53 additions & 0 deletions node/utils/Cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* The CLI module handles command line parameters
*/

/*
* 2012 Jordan Hollinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an
"AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// The help text
exports.helpText = '\
run.sh [OPTIONS] \n\
\n\
OPTIONS \n\
-s|--settings FILE Specifies the settings.json file\n\
-h|--help Print this message and exit \n\
';

// An object containing the parsed command-line options
exports.argv = {};

var argv = process.argv.slice(2);
var arg, prevArg;

// Loop through args
for ( var i = 0; i < argv.length; i++ ) {
arg = argv[i];

// Override location of settings.json file
if ( prevArg == '--settings' || prevArg == '-s' ) {
exports.argv.settings = arg;
}

// Print help and exit
else if ( arg == '--help' || arg == '-h' ) {
console.log(exports.helpText);
process.exit(0);
}

prevArg = arg;
}
8 changes: 6 additions & 2 deletions node/utils/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
var fs = require("fs");
var os = require("os");
var path = require('path');
var cli = require('./Cli');

/**
* The IP ep-lite should listen to
Expand Down Expand Up @@ -88,9 +89,12 @@ exports.abiwordAvailable = function()
}
}

// Discover where the settings file lives
var settingsFilename = cli.argv.settings || "settings.json";
var settingsPath = settingsFilename.charAt(0) == '/' ? '' : path.normalize(__dirname + "/../../");

//read the settings sync
var settingsPath = path.normalize(__dirname + "/../../");
var settingsStr = fs.readFileSync(settingsPath + "settings.json").toString();
var settingsStr = fs.readFileSync(settingsPath + settingsFilename).toString();

//remove all comments
settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
Expand Down