Skip to content

Commit

Permalink
Cleaning up cli override options to correct syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserf committed Jun 17, 2016
1 parent 2c62575 commit 2b98648
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions bin/deepstream-start
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ var program = require( 'commander' );

program
.option( '-c, --config [file]', 'configuration file, parent directory will be used as prefix for other config files' )
.option( '-l, --libPrefix [directory]', 'path where to lookup for plugins like connectors and logger' )
.option( '-l, --lib-prefix [directory]', 'path where to lookup for plugins like connectors and logger' )
.option( '-d, --detach', 'detach the deepstream server process' )

.option( '--serverName <name>', 'Each server within a cluster needs a unique name' )
.option( '--colors', 'Use colors when logging' )
.option( '--showLogo', 'Show the deepstream logo on startup' )
.option( '--logLevel <level>', 'Log messages with this level and above', parseLogLevel )
.option( '--webServerEnabled [false]', 'Accept/Decline incoming HTTP connections', parseServerEnabled )
.option( '--tcpServerEnabled [false]', 'Accept/Decline incoming TCP connections', parseServerEnabled )
.option( '--server-name <name>', 'Each server within a cluster needs a unique name' )
.option( '--web-server-enabled [true|false]', 'Accept/Decline incoming HTTP connections', parseBoolean.bind( null, '--web-server-enabled' ) )
.option( '--tcp-server-enabled [true|false]', 'Accept/Decline incoming TCP connections', parseBoolean.bind( null, '--tcp-server-enabled' ) )
.option( '--host <host>', 'host for the HTTP/websocket server' )
.option( '--port <port>', 'port for the HTTP/websocket server', parsePort )
.option( '--tcpHost <host>', 'host for the TCP server' )
.option( '--tcpPort <port>', 'tcpHost', parsePort )
.option( '--disableAuth', 'Force deepstream to use "none" auth type' )
.option( '--disablePermissions', 'Force deepstream to use "none" permissions' )
.option( '--port <port>', 'port for the HTTP/websocket server', parseInteger.bind( null, '--port' ) )
.option( '--tcp-host <host>', 'host for the TCP server' )
.option( '--tcp-port <port>', 'tcpHost', parseInteger.bind( null, '--tcp-port' ) )
.option( '--disable-auth', 'Force deepstream to use "none" auth type' )
.option( '--disable-permissions', 'Force deepstream to use "none" permissions' )
.option( '--log-level <level>', 'Log messages with this level and above', parseLogLevel )
.option( '--colors [true|false]', 'Enable or disable logging with colors', parseBoolean.bind( null, '--colors' ) )

function detachErrorHandler() {
console.error( 'Error during detaching the deepstream process, run without --detach'.red );
Expand Down Expand Up @@ -100,33 +99,33 @@ function parseLogLevel( logLevel ) {
}

/**
* Used by commander to parse the portnumber and fails if invalid
* Used by commander to parse numbers and fails if invalid
* value is passed in
* @private
*/
function parsePort( port ) {
function parseInteger( name, port ) {
const portNumber = Number( port );
if( !portNumber ) {
console.error( 'Provided port number must be an integer' );
console.error( 'Provided ${name} must be an integer' );
process.exit(1);
}
return portNumber;
}

/**
* Used by commander to parse the disabling/enabling of servers and fails if invalid
* Used by commander to parse boolean and fails if invalid
* value is passed in
* @private
*/
function parseServerEnabled( enabled ) {
function parseBoolean( name, enabled ) {
var isEnabled;
if( typeof enabled === "undefined" || enabled === 'true' ) {
isEnabled = true;
}
else if( typeof enabled !== "undefined" && enabled === 'false' ) {
isEnabled = false;
} else {
console.error( 'Invalid argument for (webServerEnabled|tcpServerEnabled), please provide true or false' );
console.error( `Invalid argument for ${name}, please provide true or false` );
process.exit( 1 );
}
return isEnabled;
Expand Down

0 comments on commit 2b98648

Please sign in to comment.