<commit_before>'use strict';

var Command = require('../lib/command');
var configstore = require('../lib/configstore');
var logger = require('../lib/logger');
var chalk = require('chalk');
var RSVP = require('rsvp');
var utils = require('../lib/utils');
var api = require('../lib/api');
var _ = require('lodash');

module.exports = new Command('logout')
  .description('delete local authentication data')
  .action(function(options) {
    var user = configstore.get('user');
    var session = configstore.get('session');
    var token = utils.getInheritedOption(options, 'token') || _.get(session, 'token');
    api.setToken(token);
    var next;
    if (token) {
      next = api.request('DELETE', '/account/token', {
        auth: true
      });
    } else {
      next = RSVP.resolve();
    }

    var cleanup = function() {
      if (token || user || session) {
        configstore.del('user');
        configstore.del('session');
        var msg = 'Logged out';
        if (user) {
          msg += ' from ' + chalk.bold(user.email);
        }
        utils.logSuccess(msg);
      } else {
        logger.info('No need to logout, not logged in');
      }
    };<commit_msg>Only clearing the config store of the current session if that's the one the CLI is logging out<commit_after>'use strict';

var Command = require('../lib/command');
var configstore = require('../lib/configstore');
var logger = require('../lib/logger');
var chalk = require('chalk');
var RSVP = require('rsvp');
var utils = require('../lib/utils');
var api = require('../lib/api');
var _ = require('lodash');

module.exports = new Command('logout')
  .description('delete local authentication data')
  .action(function(options) {
    var user = configstore.get('user');
    var session = configstore.get('session');
    var currentToken = _.get(session, 'token');
    var token = utils.getInheritedOption(options, 'token') || currentToken;
    api.setToken(token);
    var next;
    if (token) {
      next = api.request('DELETE', '/account/token', {
        auth: true
      });
    } else {
      next = RSVP.resolve();
    }

    var cleanup = function() {
      if (token || user || session) {
        var msg = 'Logged out';
        if (token === currentToken) {
          configstore.del('user');
          configstore.del('session');
          if (user) {
            msg += ' from ' + chalk.bold(user.email);
          }
        } else {
          msg += ' token "' + chalk.bold(token) + '"';
        }
        utils.logSuccess(msg);
      } else {
        logger.info('No need to logout, not logged in');
      }
    };
{'fraction_non_alphanumeric': 0.17050691244239632, 'fraction_numerical': 0.0, 'mean_word_length': 2.593103448275862, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2179018', 'n_tokens_mistral': 780, 'n_tokens_neox': 768, 'n_words': 197}