#!/usr/bin/env node

var matcher = require('../semver-range-matcher');

function getRequests() {
  var result = [];
  var argv = process.argv.slice(2);
  for (var i = 0; i < argv.length; i++) {
    if (argv[i] !== '--package') {
      console.error('Unexpected option ' + argv[i]);
      process.exit(1);
    }
    if (i + 3 < argv.length) {
      result.push({
        packageName: argv[i + 1],
        versionRange: argv[i + 2],
        version: argv[i + 3]
      });
      i += 3;
    }
    else {
      console.error('Too few parameters after position ' + i + ': ' + JSON.stringify(argv));
      process.exit(1);
    }
  }
  return result;
}

var requests = getRequests();
var responses = matcher.match(requests);
process.stdout.write(JSON.stringify(responses, null, 2) + '\n');
