Command line utils module. Contains service functions for working with the command line arguments
Example
var argv = require('cmd/argv');
// connect to server
var session = argv.establishConnectionFromCmdLineAttributes();
console.log('Session.uData: ', session.uData, typeof session.uData, session.uData.lang);
userLang = session.uData.lang || 'en';
conn = session.connection;
// obtain domain information
var domainInfo = conn.getDomainInfo();
Classes
Members
findCmdLineSwitch
static
- Deprecated:
- Use `options.switchIndex' instead
findCmdLineSwitchValue
static
- Deprecated:
- Use `options.switchValue' instead
establishConnectionFromCmdLineAttributesUsageInfo: String
static
Describe set of command line attributes taken by cmd.argv#establishConnectionFromCmdLineAttributes
method.
To be used during display command help message:
var argv = require('./argv');
if (argv.findCmdLineSwitch('help') !== -1){
console.info([
'This command throw error in case server is started',
'Usage: ',
'>UB -f cmd/checkServerNotStarted ' + argv.establishConnectionFromCmdLineAttributesUsageInfo
].join('\r\n'));
return;
}
Methods
getConfigFileName() → String
static
Get config file name. if -cfg switch passed then use this switch value, else use default
serverSessionFromCmdLineAttributes() → ServerSession
static
Parse cmd line and environment variables for command line parameters expected by UnityBase cmd
mode
establishConnectionFromCmdLineAttributes(configopt) → ServerSession
static
Service function for establish UnityBase server connection from client-side command line script.
Parse command line attributes for switches host
, u
, p
and:
- Check specified server is started (simple request to
host
) and if not started then
start server locally with local config
- Establish connection to specified host
- Retrieve application information and in case authorization is required then call login method using
u
and p
params
- Return serverSession object with connection in case of success or throw assertion error
Arguments:
-
[config]
(Object)
Properties
checkServerStarted(URL) → boolean
static
Perform check somebody listen on URL
Arguments:
-
URL
(String)
getServerConfiguration() → Object
static
Read server configuration using file, resolved by argv.getConfigFileName
parse it in safe mode, replace environment variables by it values and return parsed config
serverURLFromConfig(config)
static
Return a URL server actually listen on
Arguments:
-
config
(Object)
 Server configuration
identifyApp(serverConfig) → Object
static
Identify application, for which command is executed.
First check for command line parameter -app, if not defined - environment variable UB_APP, if not defined - first application in config
Arguments:
-
serverConfig
(Object)
- Deprecated:
- Starting from 1.11 config contain only one application, so use `config.application` directly
Throws:
Error if application not found
safeParseJSONfile(fileName, allowMultiLineStringopt) → Object
static
JSON file parsing, allow to parse semi-JSON files with comments. In case of errors inside JSON show detailed error description
Arguments:
-
fileName
(String)
-
[allowMultiLineString=false]
(Boolean)
 Replace \n
before parse (not compatible with JSON format, but multiline string is useful)
- To Do:
-
- - rewrite when switch to SpiderMonkey 33 in in which native JSON.parse show error line number
- Use `options.switchIndex' instead
- Use `options.switchValue' instead
Describe set of command line attributes taken by cmd.argv#establishConnectionFromCmdLineAttributes
method.
To be used during display command help message:
var argv = require('./argv');
if (argv.findCmdLineSwitch('help') !== -1){
console.info([
'This command throw error in case server is started',
'Usage: ',
'>UB -f cmd/checkServerNotStarted ' + argv.establishConnectionFromCmdLineAttributesUsageInfo
].join('\r\n'));
return;
}
getConfigFileName() → String static
Get config file name. if -cfg switch passed then use this switch value, else use default
serverSessionFromCmdLineAttributes() → ServerSession static
Parse cmd line and environment variables for command line parameters expected by UnityBase
cmd
mode
establishConnectionFromCmdLineAttributes(configopt) → ServerSession static
Service function for establish UnityBase server connection from client-side command line script.
Parse command line attributes for switches host
, u
, p
and:
- Check specified server is started (simple request to
host
) and if not started then start server locally with local config - Establish connection to specified host
- Retrieve application information and in case authorization is required then call login method using
u
andp
params - Return serverSession object with connection in case of success or throw assertion error
Arguments:
-
[config]
(Object)
Properties
checkServerStarted(URL) → boolean static
Perform check somebody listen on URL
Arguments:
-
URL
(String)
getServerConfiguration() → Object static
Read server configuration using file, resolved by argv.getConfigFileName
parse it in safe mode, replace environment variables by it values and return parsed config
serverURLFromConfig(config) static
Return a URL server actually listen on
Arguments:
-
config
(Object)
 Server configuration
identifyApp(serverConfig) → Object static
Identify application, for which command is executed.
First check for command line parameter -app, if not defined - environment variable UB_APP, if not defined - first application in config
Arguments:
-
serverConfig
(Object)
- Deprecated:
- Starting from 1.11 config contain only one application, so use `config.application` directly
Throws:
Error if application not found
safeParseJSONfile(fileName, allowMultiLineStringopt) → Object static
JSON file parsing, allow to parse semi-JSON files with comments. In case of errors inside JSON show detailed error description
Arguments:
-
fileName
(String)
-
[allowMultiLineString=false]
(Boolean)
 Replace\n
before parse (not compatible with JSON format, but multiline string is useful)
- To Do:
-
- - rewrite when switch to SpiderMonkey 33 in in which native JSON.parse show error line number