<commit_before>'use strict';

var cli = require('commander');
var request = require('request');
var _ = require('lodash');
require('colors');

var Config = require('../config').Config;

//Trace Command
var runCmd = cli.command('run <projectName> <path>');
runCmd
    .description('Run 28.io query.')
    .action(function(projectName, path){
        projectName = projectName || Config.getDefaultProject();
        return Config.refreshTokens(projectName).then(function(){
            var url = Config.getProjectEndpoint(projectName) + '/_queries';
            path = path.indexOf('?') === -1 ? path + '/metadata/trace' : path.substring(0, path.indexOf('?')) + "/metadata/trace" + path.substring(path.indexOf('?'));
            path = path.indexOf('?') === -1 ? (path + '?') : path;
            path = path[0] === '/' ? path : ('/' + path);
            url += path + '&_token=' + encodeURIComponent(Config.getProjectToken(projectName));
            request({
                uri: url,
                method: 'GET'
            }, function(error, response, body){
                if(error) {
                    console.error(error);
                    return;
                }
                console.log(body.green);
            });
        });
    });
<commit_msg>:wrench:<commit_after>'use strict';

var cli = require('commander');
var request = require('request');
var _ = require('lodash');
require('colors');
var URL = require('url');

var Config = require('../config').Config;

//Trace Command
var runCmd = cli.command('run <projectName> <path>');
runCmd
    .description('Run 28.io query.')
    .action(function(projectName, path){
        projectName = projectName || Config.getDefaultProject();
        return Config.refreshTokens(projectName).then(function(){
            var u = URL.parse(path);
            if(u.protocol === null) {
                u = URL.parse(Config.getProjectEndpoint(projectName) + '/_queries' + (path[0] === '/' ? '' : '/') + path);
            }
            if(!u.path.endsWith('.jq') && !u.path.endsWith('.xq')) {
                //Assumes JSONiq then
                u.path += '.jq';
            }
            if(u.search === null) {
                u.search = '';
            } else {
                u.search += '&';
            }
            u.search += '_token=' + encodeURIComponent(Config.getProjectToken(projectName));
            var serializedURL = URL.format(u);
            request({
                uri: serializedURL,
                method: 'GET'
            }, function(error, response, body){
                if(error) {
                    console.error(error);
                    return;
                }
                console.log(body.green);
            });
        });
    });

{'fraction_non_alphanumeric': 0.16849015317286653, 'fraction_numerical': 0.0032822757111597373, 'mean_word_length': 1.8752620545073375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4583078', 'n_tokens_mistral': 768, 'n_tokens_neox': 748, 'n_words': 145}