var optimist = require('optimist');
var server = require('./server.js');

var argv = optimist.usage('Usage: $0 github_username [options]')
  .demand('_')
  .options('p', {
    alias: 'password',
    type: 'string',
    describe: 'The GitHub password to retrieve non-public repos.'
  })
  .options('a', {
    alias: 'all',
    type: 'boolean',
    describe: 'Query all repos of GitHub user (default: query watched repos of user).',
    'default': false
  })
  .options('r', {
    alias: 'repo',
    type: 'string',
    describe: [
      'Repo (e.g. "foo/bar") that should be queried. Use it multiple times to ',
      'query more than one repo.'
    ].join('')
  })
  .options('t', {
    alias: 'tags_regexp',
    describe: 'Regular expression that matches a git-tag as version.',
    'default': /v\d.*/
  })
  .options('P', {
    alias: 'port',
    describe: 'Port where the server should listen.',
    'default': 4337
  })
  .argv;

console.log('Starting depository NPM registry ...');

var repos = typeof argv.repo == 'string' ? [argv.repo] : argv.repo;

server.setup({
  username: argv._[0],
  password: argv.password,
  queryAll: argv.all,
  repos: repos
}, function(err, data, server) {
  if (err) {
    console.error(err);
    process.exit(1);
  }
  server.listen(argv.port, function() {
    console.log("Started depository NPM registry on port " + server.address().port);
    if (Object.keys(data) == 0) {
      console.log("Serving no GitHub projects!");
    } else {
      console.log("Serving the following GitHub projects:");
      for(var project in data) {
        console.log([
          project,
          ': ',
          JSON.stringify(Object.keys(data[project].versions))
        ].join(''));
      }
    }
  });
});

var optimist = require('optimist');
var server = require('./server.js');

var argv = optimist.usage('Usage: $0 github_username [options]')
  .demand('_')
  .options('p', {
    alias: 'password',
    type: 'string',
    describe: 'The GitHub password to retrieve non-public repos.'
  })
  .options('a', {
    alias: 'all',
    type: 'boolean',
    describe: 'Query all repos of GitHub user (default: query watched repos of user).',
    'default': false
  })
  .options('r', {
    alias: 'repo',
    type: 'string',
    describe: [
      'Repo (e.g. "foo/bar") that should be queried. Use it multiple times to ',
      'query more than one repo.'
    ].join('')
  })
  .options('P', {
    alias: 'port',
    describe: 'Port where the server should listen.',
    'default': 4337
  })
  .argv;

console.log('Starting depository NPM registry ...');

var repos = typeof argv.repo == 'string' ? [argv.repo] : argv.repo;

server.setup({
  username: argv._[0],
  password: argv.password,
  queryAll: argv.all,
  repos: repos
}, function(err, data, server) {
  if (err) {
    console.error(err);
    process.exit(1);
  }
  server.listen(argv.port, function() {
    console.log("Started depository NPM registry on port " + server.address().port);
    if (Object.keys(data) == 0) {
      console.log("Serving no GitHub projects!");
    } else {
      console.log("Serving the following GitHub projects:");
      for(var project in data) {
        console.log([
          project,
          ': ',
          JSON.stringify(Object.keys(data[project].versions))
        ].join(''));
      }
    }
  });
});

Use repos from the config object