<commit_before>/*
    ari add [selector] [name]
 */

'use strict';
var
      selector
    , action
    , target
    , plural
    , color      = require('colors')
    , inflection = require('inflection')
    , mkdirp     = require('mkdirp')
    , _f         = require('fs-utils')
    , selectors  = {
          plugin:'plugin'
        , project:'project'
      }
    , log        = console.log

    , ADD;


ADD = module.exports = (function(){
    var
    /*
        Vars
     */



    /*
        Methods
     */
        run = function() {
            action   = this.args[0];
            selector = this.args[1];
            target   = this.args[2];

            plural = {
                selector: inflection.pluralize(selector)
            }

            if (!selectors[selector]) {
                log('No Selector Found'.red)
                log('Please provide a selector'.blue)
                log(color.blue('ari '+action+' <plugin | project> [target]'))
                process.exit(0);
            }
            log(color.green('Selector found '+selector))

            if (!target) {
                log('No target found'.red)
                log(color.blue('Please provide a target'))
                log(color.blue('ari '+action+' '+selector+' [target]'));
                process.exit(0);
            }
            log(color.green('Target found '+target))


            if (this.config[plural.selector][target]) {
                log(color.red(selector+' '+target+ ' already exists!'))
                log(color.blue('Please choose another name'))
                process.exit(0);
            }

            log(color.green('Target does not exist continue'))

            this.finish()
            console.log(this.config)


        },

        finish = function(){

            this.config[plural.selector] = this.config[plural.selector] || {};
            this.config[plural.selector][target] = {name:target, path:'/'+plural.selector + '/' + target}
            _f.writeJSONSync(this.configPath, this.config);
            mkdirp(this.config.root + '/'+ this.config[plural.selector][target].path, function(err, result){
                if(err){
                    log(err.red)
                }
                log(result.green)
            })
        };

    return {
          finish:finish
        , run:run
    }

})();<commit_msg>Refactor command(ari add)<commit_after>
module.exports = function(){

    var Err = require('../lib/logger').Err;
    var Ok = require('../lib/logger').Ok;
    var selector = process.ARI.args[1];
    var action = process.ARI.args[0];
    var target = process.ARI.args[2];
    var pselector = selector + 's';
    var mkdirp = require('mkdirp');
    var _f = require('fs-utils');

    var selectors = {
        project: 'projects',
        plugin: 'plugins'
    };

    if (!selectors[selector]){
        Err('');
        Err('Please provide a valid selector!');
        Err('-> ari add [project/plugin] [name]');
        Err('');
        return;
    }

    if (!target){
        Err('');
        Err('Please provide name!');
        Err('-> ari add [project/plugin] [name]');
        Err('');
        return;
    }

    if (process.ARI.config[pselector][target]){
        Err('');
        Err('The ${a} ${b} already exists!', selector, target);
        Err('Please try another name');
        Err('');
        return;
    }

    process.ARI.config[pselector] = process.ARI.config[pselector] || {};
    process.ARI.config[pselector][target] = { name:target, path:'/' + pselector + '/' + target };
    _f.writeJSONSync(process.ARI.configPath, process.ARI.config);
    mkdirp(process.ARI.config.root + '/' + process.ARI.config[pselector][target].path, function(err, result){
        if (err){
            Err('');
            Err(err);
            Err('');
        } else {
            Ok('The ${a} ${b} has been created!', selector, target);
        }
    });
}
{'fraction_non_alphanumeric': 0.15959079283887467, 'fraction_numerical': 0.002301790281329923, 'mean_word_length': 1.7122052704576975, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '4059519', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1121, 'n_words': 223}