<commit_before>//
// Copyright (c) Microsoft and contributors.  All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

// If running from MSI installed version, don't use the
// compile on the fly streamline files. MSI install precompiles
// the streamline files
if (!process.env.PRECOMPILE_STREAMLINE_FILES) {
  require('streamline').register({cache: true});
}

var omelette = require('omelette');

var fs = require('fs');
var path = require('path');
var util = require('util');
var commander = require('commander');

var _ = require('underscore');

var ExtendedCommand = require('./util/extendedcommand');
var log = require('./util/logging');

var utils = require('./util/utils');
var Constants = require('./util/constants');
var Interactor = require('./util/interaction');

var config = utils.readConfig();

function AzureCli(name, parent) {
  this.parent = parent;
  this.output = log;
  this.interaction = new Interactor(this);

  if (parent) {
    this._mode = parent._mode;
  }

  AzureCli['super_'].call(this, name);

  if (!parent) {
    this.initSetup();

    this.enableNestedCommands(this);

    // Check node.js version.
    // Do it after changing exception handler.
    this.checkVersion();

    this.harvestPlugins();
    this.harvestModules();

    this.enableAutoComplete();
  }
}

util.inherits(AzureCli, ExtendedCommand);

_.extend(AzureCli.prototype, {
  initSetup: function() {
    var self = this;

    self.debug = process.env.AZURE_DEBUG === '1';

    // Install global unhandled exception handler to make unexpected errors more user-friendly.
    if (!self.debug && process.listeners('uncaughtException').length === 0) {
      self.uncaughExceptionHandler = function (err) {
        self.interaction.clearProgress();

        // Exceptions should always be logged to the console
        var noConsole = false;
        if (!log['default'].transports.console) {
          noConsole = true;
          self.output.add(self.output.transports.Console);
        }

        var loggedFullError = false;
        if (err.message) {
          log.error(err.message);
        } else if (err.Message) {
          log.error(err.Message);
        } else {
          log.json('error', err);
          loggedFullError = true;
        }

        if (!loggedFullError) {
          if (err.stack) {
            log.verbose('stack', err.stack);
          }

          log.json('silly', err);
        }

        self.recordError(err);

        if (noConsole) {
          self.output.remove(self.output.transports.Console);
        }

        self.exit('error', null, 1);
      };

      process.addListener('uncaughtException', self.uncaughExceptionHandler);
    }
  },

  recordError: function(err) {
    if (err && err.stack) {
      try {
        fs.writeFileSync('azure.err', (new Date()) + ':\n' +
            util.inspect(err) + '\n' + err.stack + '\n');
        (log.format().json ? log.error : log.info)('Error information has been recorded to azure.err');
      } catch(err2) {
        log.warn('Cannot save error information :' + util.inspect(err2));
      }
    }
  },

  exit: function (level, message, exitCode) {
    var self = this;

    self.interaction.clearProgress();
    if (message) {
      log.log(level, message);
    }

    if (self.uncaughtExceptionHandler) {
      process.removeListener('uncaughtException', self.uncaughExceptionHandler);
    }

    process.exit(exitCode);
  },

  option: function(flags, description, fn, defaultValue){
    var self = this
      , option = new commander.Option(flags, description)
      , oname = option.name()
      , name = utils.camelcase(oname);

    if (!self.optionValues) {
      self.optionValues = {};
    }

    // default as 3rd arg
    if ('function' != typeof fn) defaultValue = fn, fn = null;

    // preassign default value only for --no-*, [optional], or <required>
    if (false == option.bool || option.optional || option.required) {
      // when --no-* we make sure default is true
      if (false == option.bool) defaultValue = true;
      // preassign only if we have a default
      if (undefined !== defaultValue) self.optionValues[name] = defaultValue;
    }

    // register the option
    this.options.push(option);

    // when it's passed assign the value
    // and conditionally invoke the callback
    this.on(oname, function (val) {
      // coercion
      if (null != val && fn) val = fn(val);

      // unassigned or bool
      if ('boolean' == typeof self.optionValues[name] || 'undefined' == typeof self.optionValues[name]) {
        // if no value, bool true, and we have a default, then use it!
        if (null == val) {
          self.optionValues[name] = option.bool
            ? defaultValue || true
            : false;
        } else {
          self.optionValues[name] = val;
        }
      } else if (null !== val) {
        // reassign
        self.optionValues[name] = val;
      }
    });

    return this;
  },
<commit_msg>Fixed jshint errors<commit_after>//
// Copyright (c) Microsoft and contributors.  All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

// If running from MSI installed version, don't use the
// compile on the fly streamline files. MSI install precompiles
// the streamline files
if (!process.env.PRECOMPILE_STREAMLINE_FILES) {
  require('streamline').register({cache: true});
}

var omelette = require('omelette');

var fs = require('fs');
var path = require('path');
var util = require('util');
var commander = require('commander');

var _ = require('underscore');

var ExtendedCommand = require('./util/extendedcommand');
var log = require('./util/logging');

var utils = require('./util/utils');
var Constants = require('./util/constants');
var Interactor = require('./util/interaction');

var config = utils.readConfig();

function AzureCli(name, parent) {
  this.parent = parent;
  this.output = log;
  this.interaction = new Interactor(this);

  if (parent) {
    this._mode = parent._mode;
  }

  AzureCli['super_'].call(this, name);

  if (!parent) {
    this.initSetup();

    this.enableNestedCommands(this);

    // Check node.js version.
    // Do it after changing exception handler.
    this.checkVersion();

    this.harvestPlugins();
    this.harvestModules();

    this.enableAutoComplete();
  }
}

util.inherits(AzureCli, ExtendedCommand);

_.extend(AzureCli.prototype, {
  initSetup: function() {
    var self = this;

    self.debug = process.env.AZURE_DEBUG === '1';

    // Install global unhandled exception handler to make unexpected errors more user-friendly.
    if (!self.debug && process.listeners('uncaughtException').length === 0) {
      self.uncaughExceptionHandler = function (err) {
        self.interaction.clearProgress();

        // Exceptions should always be logged to the console
        var noConsole = false;
        if (!log['default'].transports.console) {
          noConsole = true;
          self.output.add(self.output.transports.Console);
        }

        var loggedFullError = false;
        if (err.message) {
          log.error(err.message);
        } else if (err.Message) {
          log.error(err.Message);
        } else {
          log.json('error', err);
          loggedFullError = true;
        }

        if (!loggedFullError) {
          if (err.stack) {
            log.verbose('stack', err.stack);
          }

          log.json('silly', err);
        }

        self.recordError(err);

        if (noConsole) {
          self.output.remove(self.output.transports.Console);
        }

        self.exit('error', null, 1);
      };

      process.addListener('uncaughtException', self.uncaughExceptionHandler);
    }
  },

  recordError: function(err) {
    if (err && err.stack) {
      try {
        fs.writeFileSync('azure.err', (new Date()) + ':\n' +
            util.inspect(err) + '\n' + err.stack + '\n');
        (log.format().json ? log.error : log.info)('Error information has been recorded to azure.err');
      } catch(err2) {
        log.warn('Cannot save error information :' + util.inspect(err2));
      }
    }
  },

  exit: function (level, message, exitCode) {
    var self = this;

    self.interaction.clearProgress();
    if (message) {
      log.log(level, message);
    }

    if (self.uncaughtExceptionHandler) {
      process.removeListener('uncaughtException', self.uncaughExceptionHandler);
    }

    process.exit(exitCode);
  },

  option: function(flags, description, fn, defaultValue){
    var self = this;
    var option = new commander.Option(flags, description);
    var oname = option.name();
    var name = utils.camelcase(oname);

    if (!self.optionValues) {
      self.optionValues = {};
    }

    // default as 3rd arg
    if ('function' !== typeof fn) {
      defaultValue = fn;
      fn = null;
    }

    // preassign default value only for --no-*, [optional], or <required>
    if (false === option.bool || option.optional || option.required) {
      // when --no-* we make sure default is true
      if (false === option.bool) defaultValue = true;
      // preassign only if we have a default
      if (undefined !== defaultValue) self.optionValues[name] = defaultValue;
    }

    // register the option
    this.options.push(option);

    // when it's passed assign the value
    // and conditionally invoke the callback
    this.on(oname, function (val) {
      // coercion
      if (null !== val && fn) val = fn(val);

      // unassigned or bool
      if ('boolean' === typeof self.optionValues[name] || 'undefined' === typeof self.optionValues[name]) {
        // if no value, bool true, and we have a default, then use it!
        if (null === val) {
          self.optionValues[name] = option.bool ? defaultValue || true : false;
        } else {
          self.optionValues[name] = val;
        }
      } else if (null !== val) {
        // reassign
        self.optionValues[name] = val;
      }
    });

    return this;
  },

{'fraction_non_alphanumeric': 0.13527584947022286, 'fraction_numerical': 0.001826817683595177, 'mean_word_length': 2.574600065295462, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4953880', 'n_tokens_mistral': 3206, 'n_tokens_neox': 3123, 'n_words': 891}