<commit_before>'use strict';

var node_path   = require('path');
var node_url    = require('url');
var lang        = require('../util/lang');
var pkg_helper  = require('../util/package');
var async       = require('async');




exports.shorthands = {
    c: 'cwd',
    r: 'recursive'
};

exports.options = {
    recursive: {
        type: Boolean,
        info: 'install all dependencies recursively. If `false`, cortex will only download the current module.',
        default: true
    },

    cwd: {
        type: node_path,
        info: 'current working directory.',
        // `cortex install` could be executed anywhere
        default: process.cwd()
    },

    // if --save --save-async, --save-async will be ignored
    save: {
        type: Boolean,
        info: 'package will appear in your "cortex.dependencies" of package.json.',
        validator: save_check_package
    },

    'save-async': {
        type: Boolean,
        info: 'package will appear in your "cortex.asyncDependencies" of package.json.',
        validator: save_check_package
    },

    'save-dev': {
        type: Boolean,
        info: 'package will appear in your "cortex.devDependencies" of package.json.',
        validator: save_check_package
    },

    clone: {
        type: Boolean,
        info: 'try to clone the package repo down to the workspace.',
        default: false
    },

    production: {
        type: Boolean,
        info: 'ignore "devDependencies". Only works when not explicitly specify module to install',
        default: false
    },

    modules: {
        // command line type: String
        // programmatical type: Array.<string>
        info: 'modules to install. if not specified, cortex will read them from your package.json. if you install a module without version, cortex will try to install the latest one.',
        setter: function(modules) {
            var done = this.async();

            exports._get_modules({
                remain      : this.get('_') || [],
                cwd         : this.get('cwd'),
                save        : this.get('_save'),
                production  : this.get('production'),
                modules     : modules

            }, done);
        }
    }
};


function save_check_package (save) {
    var done = this.async();

    // if --save, package.json must exists
    if(save){
        var cwd = pkg_helper.repo_root( this.get('cwd') );

        // 'cortex install' might be called inside a subtle directory of the project.
        if(cwd === null){
            return done('package.json not found, could not save dependencies');
        }

        this.set('cwd', cwd);
        // options._save: internal use
        this.set('_save', true);<commit_msg>#277: option/install: cwd will always be traversed to the repo root<commit_after>'use strict';

var node_path   = require('path');
var node_url    = require('url');
var lang        = require('../util/lang');
var pkg_helper  = require('../util/package');
var async       = require('async');


exports.shorthands = {
    c: 'cwd',
    r: 'recursive'
};

exports.options = {

    // Indicates that user want to save something into package.json
    _save: {
        type: Boolean,
        enumerable: false,
        default: false
    },

    recursive: {
        type: Boolean,
        info: 'install all dependencies recursively. If `false`, cortex will only download the current module.',
        default: true
    },

    cwd: {
        type: node_path,
        info: 'current working directory.',
        // `cortex install` could be executed anywhere
        default: process.cwd(),
        setter: function (cwd) {
            // if not inside a project, returns null
            return pkg_helper.repo_root( this.get('cwd') );
        }
    },

    // if --save --save-async, --save-async will be ignored
    save: {
        type: Boolean,
        info: 'package will appear in your "cortex.dependencies" of package.json.',
        validator: save_check_package
    },

    'save-async': {
        type: Boolean,
        info: 'package will appear in your "cortex.asyncDependencies" of package.json.',
        validator: save_check_package
    },

    'save-dev': {
        type: Boolean,
        info: 'package will appear in your "cortex.devDependencies" of package.json.',
        validator: save_check_package
    },

    clone: {
        type: Boolean,
        info: 'try to clone the package repo down to the workspace.',
        default: false
    },

    production: {
        type: Boolean,
        info: 'ignore "devDependencies". Only works when not explicitly specify module to install',
        default: false
    },

    modules: {
        // command line type: String
        // programmatical type: Array.<string>
        info: 'modules to install. if not specified, cortex will read them from your package.json. if you install a module without version, cortex will try to install the latest one.',
        setter: function(modules) {
            var done = this.async();
            var remain = this.get('_') || [];

            exports._get_modules({
                remain      : remain,
                cwd         : this.get('cwd'),
                save        : this.get('_save'),
                production  : this.get('production'),
                modules     : modules

            }, done);
        }
    }
};


function save_check_package (save) {
    var done = this.async();

    // if --save, package.json must exists
    if(save){
        var cwd = this.get('cwd');

        // 'cortex install' might be called inside a subtle directory of the project.
        if(cwd === null){
            return done('package.json not found, could not save dependencies');
        }

        this.set('cwd', cwd);
        // options._save: internal use
        this.set('_save', true);
{'fraction_non_alphanumeric': 0.11636675235646958, 'fraction_numerical': 0.0005141388174807198, 'mean_word_length': 1.9684638860630723, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1640564', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1559, 'n_words': 516}