#!/usr/bin/env node

var browserslist = require('./');
var pkg          = require('./package.json');
var args         = process.argv.slice(2);

function isArg(arg) {
    return args.indexOf(arg) >= 0;
}

if ( args.length === 0 || isArg('--help') || isArg('-h') ) {
    process.stdout.write([
        pkg.description,
        '',
        'Usage: ' + pkg.name + ' "QUERIES"'
    ].join('\n') + '\n');

} else if ( isArg('--version') ) {
    process.stdout.write(pkg.name + ' ' + pkg.version + '\n');

} else {
    try {
        browserslist(args[0]).forEach(function (browser) {
            process.stdout.write(browser + '\n');
        });
    } catch (e) {
        if ( e.name === 'BrowserslistError' ) {
            process.stderr.write(pkg.name + ': ' + e.message + '\n');
            process.exit(1);
        } else {
            throw e;
        }
    }
}

@@ -197,16 +197,345 @@
 = 0;%0A%7D%0A%0A
+function error(msg) %7B%0A    process.stderr.write(pkg.name + ': ' + msg + '%5Cn');%0A    process.exit(1);%0A%7D%0A%0Afunction query(queries) %7B%0A    try %7B%0A        return browserslist(queries);%0A    %7D catch (e) %7B%0A        if ( e.name === 'BrowserslistError' ) %7B%0A            error(e.message);%0A        %7D else %7B%0A            throw e;%0A        %7D%0A    %7D%0A%7D%0A%0A
 if ( arg
@@ -666,16 +666,29 @@
  'Usage:
+',%0A        ' 
  ' + pkg
@@ -707,16 +707,67 @@
 UERIES%22'
+,%0A        '  ' + pkg.name + ' --coverage %22QUERIES%22'
 %0A    %5D.j
@@ -816,16 +816,31 @@
 ersion')
+ %7C%7C isArg('-v')
  ) %7B%0A   
@@ -911,57 +911,194 @@
 lse 
-%7B%0A    try %7B%0A        browserslist(args%5B0%5D).forEach
+if ( isArg('--version') %7C%7C isArg('-v') ) %7B%0A    process.stdout.write(pkg.name + ' ' + pkg.version + '%5Cn');%0A%0A%7D else if ( isArg('--coverage') %7C%7C isArg('-c') ) %7B%0A    var browsers = args.find
 (fun
@@ -1104,23 +1104,17 @@
 nction (
-browser
+i
 ) %7B%0A    
@@ -1121,66 +1121,41 @@
     
-    process.stdout.write(browser + '%5Cn');%0A   
+return i%5B0%5D !== '-';%0A
     
- 
 %7D);%0A    
 %7D ca
@@ -1154,78 +1154,183 @@
     
-%7D catch (e) %7B%0A        if ( e.name === 'BrowserslistError' ) %7B%0A        
+if ( !browsers ) error('Define a browsers query to get coverage');%0A    var result = browserslist.coverage(query(browsers));%0A    var round  = Math.round(result * 100) / 100.0;%0A
     
@@ -1344,92 +1344,257 @@
 .std
-err
+out
 .write(
-pkg.name + ': ' + e.message + '%5Cn');%0A            process.exit(1
+%0A        'These browsers account for ' + round + '%25 of all users globally%5Cn');%0A%0A%7D else if ( args.length === 1 && args%5B0%5D%5B0%5D !== '-' ) %7B%0A    query(args%5B0%5D).forEach(function (browser) %7B%0A        process.stdout.write(browser + '%5Cn'
 );%0A    
-  
-  
+%7D);%0A%0A
 %7D el
@@ -1606,39 +1606,64 @@
     
-        throw e;%0A        %7D%0A    %7D
+error('Unknown arguments. Use --help to pick right one.')
 %0A%7D%0A

Add --coverage option to CLI