# Command Line Interface

# Getting Started

The Petro.ai Command Line Interface is the access point for organizations to run jobs on the Petro.ai Engine. The Petro.ai CLI Toolset is a growing set of tools that allow organizations to interface with the Petro.ai engine.

Jobs are organized into Job Families, each with similar functionality related to a data type or function. To run a job, the command line interface is passed arguments, including a JSON object (as a file or as a string) that contains all the necessary arguments for that particular job family.

The code snippet below is an exhaustive list of options for the Petro.ai CLI:

// to access the help, use the below command
rai.petro.commandline (-h | --help)

// to list available jobs, use the below command
rai.petro.commandline (--list-jobs)

// to run or create jobs, use the below command
rai.petro.commandline ([--create-job <--job-file | job-data>] | [--run-job <--job-file | job-data>]) (--repo=MONGODB) [--database-name="petroai"] [--log=LEVEL]

# Job File

All jobs will accept a Job File that provides the Petro.ai CLI with various options that need to be passed to the executing job. Below are descriptions of all options as well as a blank template job file.

{
	"jobName": "Name of the Job to Run",
	"wellId": "My Unique Identifier",
	"fileUri": "path/to/my/data.csv",
	"mapping": {
		"petroaiField": {
			"field": "MyFieldName",
			"uom": "MyUnit"
		},
		"petroaiField": {
			"field": "MyFieldName",
			"uom": "MyUnit"
	},
	"csv": {
		"skipRows": 0,
		"hasUnitsUnderHeader": false,
		"hasHeader": true,
	},
	"units": {
		"unitDefinition": "name",
		"definition": "UnitDefinition",
		"priority": ["unitHeader", "mapping", "definition", "useNamedDefinition", "global"]
		"timeZone": "MyTimeZone"
	},
	"extraData": {
		"storeAll": true
	}
}

# Notes on Console Output

The default if there is no '--log=LEVEL' specified, is to output only FATAL messages to the console. This leaves a clean console for the user to monitor progress of the command. It is recommended to leave this at the default level as all activity is also logged to a file.

All activity, DEBUG level and above, is logged to a logfile (petro-lib.log) located in the same location as the RAI.Petro.CommandLine.exe. The logfile file size is managed by the CLI and will create rolling files as logs are created.

The table below describe the options available to the --log parameter in the CLI:

Output to Console DEBUG Selected INFO Selected WARN Selected ERROR Selected FATAL Selected
DEBUG X
INFO X X
WARN X X X
ERROR X X X X
FATAL X X X X X

Example with --log:

rai.petro.commandline --run-job --job-data={'jobName':'installDatabase'} --repo="mongodb://localhost" --log='debug'

# Connection Strings

For Jobs that require a Provider and Connection String, the connection string must be supported by the provider. Please reference the following:

Provider: OleDB
When to use: Connecting to Access databases (.accdb and .mdb)
Example:

'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/name/aries.accdb;Persist Security Info=False;'  

WARNING

If you experience this error: "The requested OLE DB provider Microsoft.ACE.OLEDB.12.0 is not registered", you need to download and install the 32 bit version of Microsoft Access Database Engine 2010 Redistributable. This is provided by Microsoft here.

Provider: ODBC
When to use: Connecting to relational databases (Oracle, SQL Server)
Examples:

'Driver={SQL Server};Server=\\serverName;Database=dbName;Trusted_Connection=Yes;'  
or  
'Driver={Microsoft ODBC for Oracle};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=199.199.199.199)(PORT=1523))(CONNECT_DATA=(SID=dbName)));Uid=myUsername;Pwd=myPassword;'

Provider: SQLServer
When to use: Connecting to SQL Server
Example:

'Server=\\serverName;Database=dbName;Trusted_Connection=Yes;'