'use strict';

var fs = require('fs');
var cli = require('commander');

var XQLint = require('../lib/xqlint').XQLint;
var TreeOps = require('../lib/tree_ops').TreeOps;

var pkg = require('../package.json');

var printAST = function(ast, indent){
    console.log(indent + ast.name);
    ast.children.forEach(function(child){
        printAST(child, indent + indent);
    });
};

cli
.command('parse <file>')
.description('Sign-in into 28.io.')
.action(function(file) {
    var source = fs.readFileSync(file, 'utf-8');
    var linter = new XQLint(file, source);
    var markers = linter.getMarkers();
    var ast = linter.getAST();
    //TreeOps.removeParentPtr(ast, '  ');
    //printAST(ast, '  ');
    //console.log(JSON.stringify(ast, null, 2));
    if(markers.length === 0) {
        console.log('File is OK');
    } else {
        console.log(JSON.stringify(markers, null, 2));
    }
});

cli.version(pkg.version);
module.exports = cli;

@@ -32,16 +32,75 @@
 ('fs');%0A
+var ffs = require('final-fs');%0Avar path = require('path');%0A
 var cli 
@@ -451,20 +451,20 @@
 'parse %3C
-file
+path
 %3E')%0A.des
@@ -477,55 +477,491 @@
 on('
-Sign-in into 28.io.')%0A.action(function(file) %7B%0A
+Check queries')%0A.action(function(p) %7B%0A    p = path.resolve(path.normalize(p));%0A    var files = %5B%5D;%0A    if(fs.statSync(p).isFile())%7B%0A        files.push(p);%0A    %7D else %7B%0A        var list = ffs.readdirRecursiveSync(p, true, p);%0A        list.forEach(function(file)%7B%0A            if(%5B'jq', 'xq'%5D.indexOf(file.substring(file.length - 2)) !== -1) %7B%0A                files.push(file);%0A            %7D%0A        %7D);%0A    %7D%0A    files.forEach(function(file)%7B%0A        console.log('Check ' + file);%0A    
     
@@ -1001,24 +1001,28 @@
 , 'utf-8');%0A
+    
     var lint
@@ -1048,24 +1048,28 @@
 e, source);%0A
+    
     var mark
@@ -1095,24 +1095,30 @@
 kers();%0A    
+    //
 var ast = li
@@ -1140,122 +1140,8 @@
     
-//TreeOps.removeParentPtr(ast, '  ');%0A    //printAST(ast, '  ');%0A    //console.log(JSON.stringify(ast, null, 2));%0A
     
@@ -1163,24 +1163,28 @@
 th === 0) %7B%0A
+    
         cons
@@ -1206,24 +1206,28 @@
 s OK');%0A    
+ 
+   
 %7D else %7B%0A   
@@ -1215,32 +1215,36 @@
        %7D else %7B%0A
+    
         console.
@@ -1286,17 +1286,29 @@
 ));%0A    
-%7D
+    %7D%0A    %7D);
 %0A%7D);%0A%0Acl

Update cli command