Code coverage report for lib/options.js

Statements: 87.21% (75 / 86)      Branches: 82.81% (53 / 64)      Functions: 100% (2 / 2)      Lines: 87.21% (75 / 86)      Ignored: none     

All files » lib/ » options.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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179              1   1                           1 48         48 49   49   1 1 1 1 1   1       1   2 2 2       3 3     2 2     2 2             1 1     2 2 2     2 2     2 2     2 2     2 2     2 2     2 2     2 2     2 2   3 3 3 3 2 1   2   1   3                               3 3 3     2 2   1 1   7 7 7 7 74     7   1 1   2 2   2     2       48 3         48        
/**
 * Copyright (c) 2011, Yahoo! Inc. All rights reserved.
 * Code licensed under the BSD License:
 * https://github.com/yui/yuidoc/blob/master/LICENSE
 */
'use strict';
 
YUI.add('options', function (Y) {
 
    var path = require('path');
 
    /**
     * Handles argument parsing
     * @module yuidoc
     * @class Options
     */
 
    /**
     * Parses arguments and returns an Object of config options
     * @method Options
     * @param {Array} args Arguments to parse
     * @return {Object} The config object
     */
    Y.Options = function (args) {
        var options = {
            port: 3000,
            nocode: false
        };
 
        while (args.length > 0) {
            var v = args.shift();
            // options.* defined in ./builder.js
            switch (v) {
            case '--lint':
                options.lint = true;
                options.parseOnly = true;
                options.writeJSON = false;
                options.quiet = true;
                break;
            case '--debug':
                Y.applyConfig({
                    debug: true,
                    filter: 'debug'
                });
                break;
            case '--charset':
                Y.charset = args.shift() || 'utf8';
                Y.log('Setting default charset to ' + Y.charset, 'yuidoc', 'warn');
                break;
            case '-c':
            case '--config':
            case '--configfile':
                options.configfile = args.shift();
                break;
            case '-e':
            case '--extension':
                options.extension = args.shift();
                break;
            case '-x':
            case '--exclude':
                options.exclude = args.shift();
                break;
            case '-v':
            case '--version':
                console.error(Y.packageInfo.version);
                process.exit(1);
                break;
            case '--project-version':
                options.version = args.shift();
                break;
            case '-N':
            case '--no-color':
                Y.config.useColor = false;
                options.nocolor = true;
                break;
            case '-D':
            case '--no-delete-out':
                options.nodeleteout = true;
                break;
            case '-C':
            case '--no-code':
                options.nocode = true;
                break;
            case '-n':
            case '--norecurse':
                options.norecurse = true;
                break;
            case '-S':
            case '--selleck':
                options.selleck = true;
                break;
            case '-V':
            case '--view':
                options.dumpview = true;
                break;
            case '-p':
            case '--parse-only':
                options.parseOnly = true;
                break;
            case '-o':
            case '--outdir':
                options.outdir = args.shift();
                break;
            case '-t':
            case '--themedir':
                options.themedir = args.shift();
                break;
            case '--server':
                options.server = true;
                var a = args.shift();
                var p = parseInt(a, 10);
                if (isNaN(p) || !p) {
                    if (a) {
                        args.unshift(a);
                    }
                    Y.log('Failed to extract port, setting to the default :3000', 'warn', 'yuidoc');
                } else {
                    options.port = p;
                }
                break;
            case '-h':
            case '--help':
                Y.showHelp();
                break;
            case '-H':
            case '--helpers':
                var list = args.shift();
                if (list) {
                    options.helpers = list.split(',');
                } else {
                    throw ('Failed to pass a helper file.');
                }
                break;
            case '-T':
            case '--theme':
                var theme = args.shift();
                options.themedir = path.join(__dirname, '../', 'themes', theme);
                break;
            case '-q':
            case '--quiet':
                options.quiet = true;
                break;
            case '--syntaxtype':
                options.syntaxtype = args.shift();
                break;
            case '--tab-to-space':
                options.tabtospace = parseInt(args.shift(), 10);
                Eif (typeof options.tabtospace === 'number') {
                    options.tabspace = '';
                    for (var s = 0; s < options.tabtospace; s++) {
                        options.tabspace += ' ';
                    }
                }
                break;
            case '--no-sort':
                options.dontsortfields = true;
                break;
            default:
                Eif (!options.paths) {
                    options.paths = [];
                }
                Iif (v && v.indexOf('-') === 0) {
                    throw ('Unknown option: ' + v);
                }
                options.paths.push(v);
            }
        }
 
        if (options.quiet) {
            Y.applyConfig({
                debug: false
            });
        }
 
        return options;
    };
 
});