/**
 * @file command: hint
 * @author nighca<nighca@live.cn>
 */

var helper = require('./helper');
var htmlcs = require('../../');

module.exports = {
    name: 'hint',
    describe: 'Do hint given file(s)',
    examples: [
        ['$0 hint foo.html', 'do hint foo.html'],
        ['$0 hint foo.html bar.html', 'do hint foo.html & bar.html'],
        ['$0 hint ./', 'do hint html files under ./']
    ],

    handler: function (options, targetFiles) {
        // hint directly
        var hint = htmlcs.hintFile;

        // specified config
        if (options.config) {
            var config = helper.loadSpecifiedConfig(options.config);
            // hint with specified config
            hint = function (filePath) {
                return htmlcs.hint(helper.readFile(filePath), config);
            };
        }

        targetFiles.forEach(function (filePath) {
            var result = hint(filePath);

            console.log(filePath + ':');

            if (result.length) {
                result.forEach(function (item) {
                    console.log(
                        '[%s] line %d, column %d: %s (%s, %s)',
                        item.type,
                        item.line,
                        item.column,
                        item.message,
                        item.rule,
                        item.code
                    );
                });
            }
            else {
                console.log('No hint result.');
            }

            console.log('');
        });
    }
};

@@ -808,32 +808,63 @@
   %7D;%0A        %7D%0A%0A
+        var hasError = false;%0A%0A
         targetFi
@@ -1010,24 +1010,58 @@
 t.length) %7B%0A
+                hasError = true;%0A%0A
             
@@ -1583,22 +1583,86 @@
 %0A        %7D);
+%0A%0A        if (hasError) %7B%0A            process.exit(1);%0A        %7D
 %0A    %7D%0A%7D;%0A

return non-zero exit status in case of check result