<commit_before>#!/usr/bin/env node
var chalk = require('chalk');
var request = require('request');
var opts = require('nomnom').parse();
var arg = opts[0];

if (!arg) {
    console.log('Usage: ' + chalk.yellow('deref http://t.co/something'));
    process.exit(1);
}

var derefQuery = {
    method: 'POST',
    uri: 'http://deref.link/deref', 
    body: {"url": arg},
    json: true
};

var handleResponse = function (error, response, body) {
    if (!error && response.statusCode === 200) {
        var length = body.route_log.length;
        console.log(
            'Found ' + chalk.yellow(length) + (length == 1 ? ' hop: ' : ' hops:')
        );
        for(var i = 0; i < length; i++) {
            console.log(
                (i + 1).toString() + ': ' + 
                ((i + 1 == length)
                    ? chalk.green(body.route_log[i]) 
                    : chalk.yellow(body.route_log[i])).toString()
            );
        }
        
        return body;
    } 

    console.log(chalk.red(
        'An error occurred. Response code was ' + 
        (response ? response.statusCode : 'not returned') + '.'
    ));

    return false;
};

result = request(derefQuery, handleResponse);
<commit_msg>Making the usage information a bit more clear - quotes are important in case the URL contains any symbols that might make your shell unhappy.<commit_after>#!/usr/bin/env node
var chalk   = require('chalk'),
    request = require('request'),
    opts    = require('nomnom').parse(),
    arg     = opts[0];

// We need to have a URL to deref, so let's show the usage info and quit
if (!arg) {
    console.log('Usage: ' + chalk.yellow('deref "http://t.co/something"'));
    process.exit(1);
}

var derefQuery = {
    method: 'POST',
    uri:    'http://deref.link/deref', 
    body:   {"url": arg},
    json:   true
};

var handleResponse = function (error, response, body) {
    if (!error && response.statusCode === 200) {
        var length = body.route_log.length;
        console.log(
            'Found ' + chalk.yellow(length) + (length == 1 ? ' hop: ' : ' hops:')
        );
        for(var i = 0; i < length; i++) {
            console.log(
                (i + 1).toString() + ': ' + 
                ((i + 1 == length)
                    ? chalk.green(body.route_log[i]) 
                    : chalk.yellow(body.route_log[i])).toString()
            );
        }
        
        return body;
    } 

    console.log(chalk.red(
        'An error occurred. Response code was ' + 
        (response ? response.statusCode : 'not returned') + '.'
    ));

    return false;
};

result = request(derefQuery, handleResponse);

{'fraction_non_alphanumeric': 0.16142478211443728, 'fraction_numerical': 0.006820765441455097, 'mean_word_length': 2.0171428571428573, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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': '2285885', 'n_tokens_mistral': 870, 'n_tokens_neox': 801, 'n_words': 202}