Code coverage report for lib/args.js

Statements: 100% (49 / 49)      Branches: 97.5% (78 / 80)      Functions: 100% (6 / 6)      Lines: 100% (49 / 49)     

All files » lib/ » args.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 1211                                                                                         1 67 67     1 19     19 266 3       19     1 48 48 48     1 61 1     61 61 61 61 61 61 61 61     61 61 61 61 61 61 61 61   61 1     61 60 58   2         61     1 47 47     1 1 1 1 1 1  
var nopt = require('nopt'),
    known = {
        'ant': Boolean,
        'assets': Boolean,
        'build-dir': String,
        'cache': Boolean,
        'clean': Boolean,
        'color': Boolean,
        'compressor': Boolean,
        'config': require('path'),
        'coverage': Boolean,
        'csslint': Boolean,
        'cssproc': String,
        'excludes': Array,
        'exec': Boolean,
        'fail': Boolean,
        'global-config': Boolean,
        'help': Boolean,
        'istanbul': Boolean,
        'jsstamp': Boolean,
        'lint': [ 'config', false ],
        'lint-stderr': Boolean,
        'list': Boolean,
        'modules': Array,
        'progress': Boolean,
        'quiet': Boolean,
        'recursive': Boolean,
        'semi': Boolean,
        'silent': Boolean,
        'strict': Boolean,
        'version': Boolean,
        'walk': Boolean,
        'watch': Boolean,
        'yui-module': require('path')
    },
    shorts = {
        "c": ["--config"],
        "h" : ["--help"],
        "m" : ["--modules"],
        "mods" : ["--modules"],
        "v" : ["--version"],
        "w": ["--walk"],
        "x": ["--excludes"]
    };
 
var raw = function (args) {
    var parsed = nopt(known, shorts, (args || process.argv));
    return parsed;
};
 
var has = function (a) {
    var cooked = raw().argv.cooked,
        ret = false;
 
    cooked.forEach(function (o) {
        if ((o === '--' + a) || (o === '--no-' + a)) {
            ret = true;
        }
    });
 
    return ret;
};
 
var clean = function(args) {
    var parsed = raw(args);
    delete parsed.argv;
    return parsed;
};
 
var setDefaults = function(parsed) {
    if (parsed === undefined) {
        parsed = clean();
    }
    //Default true
    parsed.jsstamp = (parsed.jsstamp === undefined || parsed.jsstamp) ? true : false;
    parsed.coverage = (parsed.coverage === undefined || parsed.coverage) ? true : false;
    parsed.exec = (parsed.exec === undefined || parsed.exec) ? true : false;
    parsed.csslint = (parsed.csslint === undefined || parsed.csslint) ? true : false;
    parsed.color = (parsed.color === undefined || parsed.color) ? true : false;
    parsed['global-config'] = (parsed['global-config'] === undefined || parsed['global-config']) ? true : false;
    parsed.istanbul = (parsed.istanbul === undefined || parsed.istanbul) ? true : false;
    parsed.assets = (parsed.assets === undefined || parsed.assets) ? true : false;
 
    //Default false
    parsed.semi = (parsed.semi === undefined || parsed.semi === false) ? false : true;
    parsed.cache = (parsed.cache === undefined || parsed.cache === false) ? false : true;
    parsed.quiet = (parsed.quiet === undefined || parsed.quiet === false) ? false : true;
    parsed.silent = (parsed.silent === undefined || parsed.silent === false) ? false : true;
    parsed.clean = (parsed.clean === undefined || parsed.clean === false) ? false : true;
    parsed['lint-stderr'] = (parsed['lint-stderr'] === undefined || parsed['lint-stderr'] === false) ? false : true;
    parsed.progress = (parsed.progress === undefined || parsed.progress === false) ? false : true;
    parsed.recursive = (parsed.recursive === undefined || parsed.recursive === false) ? false : true;
 
    if (parsed.recursive) {
        parsed.walk = true;
    }
    //Other defaults
    if (!parsed['build-dir']) {
        if (parsed.recursive || !parsed.walk) {
            parsed['build-dir'] = '../../build';
        } else {
            parsed['build-dir'] = '../build';
        }
    }
 
 
    return parsed;
};
 
var parse = function (args) {
    var parsed = clean(args);
    return setDefaults(parsed);
};
 
exports.defaults = setDefaults;
exports.has = has;
exports.raw = raw;
exports.parse = parse;
exports.shorts = shorts;
exports.known = known;