<commit_before>/* jshint node: true */
'use strict';

// Dependencies
var fs = require('fs'),
	path = require('path'),
	fileToJSON = require('./file-to-json'),
	SpeedBoat = require('./speedboat'),
	deployCmd = require('./command/deploy'),
	EOL = require('os').EOL;

var IS_EXECUTING = (require.main === module);

var mod = {
	MAX_OPTION_ERROR: 99, // the maximum error code for option/argument errors

	/**
	 * Main method which is called at the end of this file.
	 * This is the main logic for the CLI script
	 *
	 * @param {Array} args The array of arguments passed to the CLI command
	 * @return {Promise}
	 */
	main: function (args) {

		var pkgFile,
			self = this,
			options = mod.parseArgsAndOptions(args);

		// Argument audits
		if (!options.command) {
			self.exit(10, new Error('No command was specified'));
		}
		if (options.command === '-h' || options.command === '--help') {
			self.showUsage();
			return;
		}
		if (!options.path) {
			self.exit(15, new Error('No project path was specified'));
		}

		// Check the project path and package.json file
		options.path = path.resolve(options.path);
		pkgFile = path.join(options.path, 'package.json');

		if (!fs.existsSync(pkgFile)) {
			self.exit(20, new Error('There is no package.json file in that project path! (' + options.path + ')'));
		}

		// The current deployer setup only allows for "deploy" as a valid command.
		// In the future, more complete lifecycle commands will be allowed based 
		// on the package.json `scripts` block.
		if (options.command !== 'deploy') {
			self.exit(25, new Error('That is not a valid command'));
		}

		if (!options.config) {
			self.exit(30, new Error('configuration object path not specified'));
		}

		var configPath = path.resolve(__dirname, options.config);

		if (!fs.existsSync(configPath)) {
			self.exit(35, new Error('cloud configuration path does not exist'));
		}

		console.log('Executing command:', JSON.stringify(options));

		var configObject;
		try {
			configObject = fileToJSON(configPath);
            console.log('Using config: ', JSON.stringify(configObject));
		} catch (e) {
			mod.showUsage();
			self.exit(40, new Error('configuration object file is not valid JSON'));
		}

		var speedboat = new SpeedBoat({
			client_id: configObject.digital_ocean.client_id,
			api_key: configObject.digital_ocean.api_key,
			ssh_key_id: configObject.digital_ocean.ssh_key_id,
			public_ssh_key: configObject.digital_ocean.public_ssh_key,
			private_ssh_key: configObject.digital_ocean.private_ssh_key,
			enable_logging: configObject.digital_ocean.enable_logging
		});
		<commit_msg>Added 'scripts_path' to speedboat init options (unused, but required)<commit_after>/* jshint node: true */
'use strict';

// Dependencies
var fs = require('fs'),
	path = require('path'),
	fileToJSON = require('./file-to-json'),
	SpeedBoat = require('./speedboat'),
	deployCmd = require('./command/deploy'),
	EOL = require('os').EOL;

var IS_EXECUTING = (require.main === module);

var mod = {
	MAX_OPTION_ERROR: 99, // the maximum error code for option/argument errors

	/**
	 * Main method which is called at the end of this file.
	 * This is the main logic for the CLI script
	 *
	 * @param {Array} args The array of arguments passed to the CLI command
	 * @return {Promise}
	 */
	main: function (args) {

		var pkgFile,
			self = this,
			options = mod.parseArgsAndOptions(args);

		// Argument audits
		if (!options.command) {
			self.exit(10, new Error('No command was specified'));
		}
		if (options.command === '-h' || options.command === '--help') {
			self.showUsage();
			return;
		}
		if (!options.path) {
			self.exit(15, new Error('No project path was specified'));
		}

		// Check the project path and package.json file
		options.path = path.resolve(options.path);
		pkgFile = path.join(options.path, 'package.json');

		if (!fs.existsSync(pkgFile)) {
			self.exit(20, new Error('There is no package.json file in that project path! (' + options.path + ')'));
		}

		// The current deployer setup only allows for "deploy" as a valid command.
		// In the future, more complete lifecycle commands will be allowed based 
		// on the package.json `scripts` block.
		if (options.command !== 'deploy') {
			self.exit(25, new Error('That is not a valid command'));
		}

		if (!options.config) {
			self.exit(30, new Error('configuration object path not specified'));
		}

		var configPath = path.resolve(__dirname, options.config);

		if (!fs.existsSync(configPath)) {
			self.exit(35, new Error('cloud configuration path does not exist'));
		}

		console.log('Executing command:', JSON.stringify(options));

		var configObject;
		try {
			configObject = fileToJSON(configPath);
            console.log('Using config: ', JSON.stringify(configObject));
		} catch (e) {
			mod.showUsage();
			self.exit(40, new Error('configuration object file is not valid JSON'));
		}

		var speedboat = new SpeedBoat({
			client_id: configObject.digital_ocean.client_id,
			api_key: configObject.digital_ocean.api_key,
			ssh_key_id: configObject.digital_ocean.ssh_key_id,
			public_ssh_key: configObject.digital_ocean.public_ssh_key,
			private_ssh_key: configObject.digital_ocean.private_ssh_key,
			enable_logging: configObject.digital_ocean.enable_logging,
            scripts_path: configObject.digital_ocean.scripts_path
		});
		
{'fraction_non_alphanumeric': 0.13459733433452226, 'fraction_numerical': 0.006007133470996809, 'mean_word_length': 3.813008130081301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '295444', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1633, 'n_words': 472}