<commit_before>var logger     = require('../lib/logger');
var sfclient   = require('../lib/sf-client');
var authServer = require('../lib/auth-server');
var index      = require('../commands/index');
var sfClient   = require('../lib/sf-client');
var cliUtil    = require('../lib/cli-util');
var spawn      = require('child_process').spawn;
var user       = require('../lib/user');

var run = module.exports.run = function(opts) {

  var clientOpts = {};

  if(opts.test) {
    clientOpts.environment = 'sandbox';
  } else if(opts.uri) {
    clientOpts.loginUri = opts.uri;
  }

  sfClient.getClient(clientOpts).then(function(client) {

    var authUri = client.getAuthUri({ responseType: 'token' });

    logger.log('login starts...');

    authServer.on('credentials', function(creds) {
      logger.log('received credentials');
      authServer.close();
      logger.log('shutting down server');
      logger.log('saving credentials for ' + opts.org);
      creds.nick = opts.org;
      creds.org = opts.org;
      user.saveCredential(opts.org, creds).then(function(){
        return index.run({ org: opts.org, oauth: creds}, function(err, res) {
          if(err) {
            logger.error('unable to save index');
            logger.done(false);
          } else {
            logger.done();
          }
        });
      });
      //logger.done();
    });

    authServer.listen(3835, function(){
      logger.log('auth server started');
      logger.log('redirect to the following uri');
      logger.log(authUri);
      // probably only works on Mac right now
      spawn('open', [authUri]);
    });
  });

};

var cli = module.exports.cli = function(program) {
  program.command('login <org>')
    .description('login to a Salesforce organization')
    .option('-t, --test', 'login to a test environment')
    .option('-u, --uri <uri>', 'specify a login uri')
    .action(function(org, opts) {
      if(!org) cliUtil.fail('no org name specified');
      opts.org = org;
      run(opts);
    });
};
<commit_msg>adding the environment and login uri to the oauth #4<commit_after>var logger     = require('../lib/logger');
var sfclient   = require('../lib/sf-client');
var authServer = require('../lib/auth-server');
var index      = require('../commands/index');
var sfClient   = require('../lib/sf-client');
var cliUtil    = require('../lib/cli-util');
var spawn      = require('child_process').spawn;
var user       = require('../lib/user');

var run = module.exports.run = function(opts) {

  var clientOpts = {};

  if(opts.test) {
    clientOpts.environment = 'sandbox';
  } else if(opts.uri) {
    clientOpts.loginUri = opts.uri;
  }

  sfClient.getClient(clientOpts).then(function(client) {

    var authUri = client.getAuthUri({ responseType: 'token' });

    logger.log('login starts...');

    authServer.on('credentials', function(creds) {
      logger.log('received credentials');
      authServer.close();
      logger.log('shutting down server');
      logger.log('saving credentials for ' + opts.org);
      creds.nick = opts.org;
      creds.org = opts.org;
      creds.environment = clientOpts.environment;
      creds.loginUri = opts.uri;
      user.saveCredential(opts.org, creds).then(function(){
        return index.run({ org: opts.org, oauth: creds}, function(err, res) {
          if(err) {
            logger.error('unable to save index');
            logger.done(false);
          } else {
            logger.done();
          }
        });
      });
      //logger.done();
    });

    authServer.listen(3835, function(){
      logger.log('auth server started');
      logger.log('redirect to the following uri');
      logger.log(authUri);
      // probably only works on Mac right now
      spawn('open', [authUri]);
    });
  });

};

var cli = module.exports.cli = function(program) {
  program.command('login <org>')
    .description('login to a Salesforce organization')
    .option('-t, --test', 'login to a test environment')
    .option('-u, --uri <uri>', 'specify a login uri')
    .action(function(org, opts) {
      if(!org) cliUtil.fail('no org name specified');
      opts.org = org;
      run(opts);
    });
};

{'fraction_non_alphanumeric': 0.1705146705146705, 'fraction_numerical': 0.0021645021645021645, 'mean_word_length': 2.6291448516579408, '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': '2529343', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1276, 'n_words': 283}