<commit_before>/**
* Copyright (c) Microsoft.  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.
*/

'use strict';

//
// Extensions to Commander to support nested commands / help system
//
var _ = require('underscore');
var commander = require('commander');
var fs = require('fs');
var path = require('path');
var util = require('util');
var utilsCore = require('./utilsCore');
var pjson = require('../../package.json');
var Constants = require('./constants');

function ExtendedCommand(name) {
  ExtendedCommand['super_'].call(this, name);
}

util.inherits(ExtendedCommand, commander.Command);

_.extend(ExtendedCommand.prototype, {

  //////////////////////////////
  // override help subsystem

  fullName: function () {
    var name = this.name;
    var scan = this.parent;
    while (scan && scan.parent !== undefined) {
      name = scan.name ? scan.name + ' ' + name : name;
      scan = scan.parent;
    }

    return name;
  },

  usage: function (str) {
    var ret;

    if (str) {
      ret = commander.Command.prototype.usage.call(this, str);
    } else {
      ret = commander.Command.prototype.usage.call(this);
      ret = ret.replace(/,/g,' ');
    }

    return ret;
  },

  helpInformation: function() {
    var self = this;

    if (!self.parent) {
      var raw = self.normalize(process.argv.slice(2));
      var containsJson = raw.some(function (item) { return item === '--json'; });
      if (containsJson) {
        self.output.format({ json: true, level: 'data' });
        self.output.json(self.helpJSON());
        return '';
      }
      var packagePath = path.join(__dirname, '../../package.json');
      var packageInfo = JSON.parse(fs.readFileSync(packagePath));

      if (raw.indexOf('-v') >= 0) {
        console.log(packageInfo.version);
      } else if (raw.indexOf('--version') >= 0) {
        console.log(util.format('%s (node: %s)', packageInfo.version, process.versions.node));
      } else {
        self.setupCommandLogFormat(true);

        self.output.info('         _    _____   _ ___ ___'.cyan);
        self.output.info('        /_\\  |_  / | | | _ \\ __|'.cyan);
        self.output.info('  _ ___'.grey + '/ _ \\'.cyan + '__'.grey + '/ /| |_| |   / _|'.cyan + '___ _ _'.grey);
        self.output.info('(___  '.grey + '/_/ \\_\\/___|\\___/|_|_\\___|'.cyan + ' _____)'.grey);
        self.output.info('   (_______ _ _)         _ ______ _)_ _ '.grey);
        self.output.info('          (______________ _ )   (___ _ _)'.grey);
        self.output.info('');

        self.output.info('Microsoft Azure: Microsoft\'s Cloud Platform');
        self.output.info('');
        self.output.info('Tool version', packageInfo.version);

        self.helpCommands();
        self.helpCategoriesSummary(self.showMore());
        self.helpOptions();
        self.showCommandMode();
      }
    } else {
      self.output.help(self.description());
      self.output.help('');
      self.output.help('Usage:', self.fullName() + ' ' + self.usage());
      self.helpOptions();
      self.showCommandMode();
    }

    return '';
  },

  showCommandMode: function(){
    this.output.help('');
    var mode = this._mode;
    if (!mode) {
      mode = utilsCore.getMode();
    }
    var text = util.format('Current Mode: %s (Azure %s Management)', mode, 
      (mode === Constants.API_VERSIONS.ASM ? 'Service' : 'Resource')); 
    this.output.help(text);
  },<commit_msg>move2cli2<commit_after>/**
* Copyright (c) Microsoft.  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.
*/

'use strict';

//
// Extensions to Commander to support nested commands / help system
//
var _ = require('underscore');
var commander = require('commander');
var fs = require('fs');
var path = require('path');
var util = require('util');
var utilsCore = require('./utilsCore');
var pjson = require('../../package.json');
var Constants = require('./constants');

function ExtendedCommand(name) {
  ExtendedCommand['super_'].call(this, name);
}

util.inherits(ExtendedCommand, commander.Command);

_.extend(ExtendedCommand.prototype, {

  //////////////////////////////
  // override help subsystem

  fullName: function () {
    var name = this.name;
    var scan = this.parent;
    while (scan && scan.parent !== undefined) {
      name = scan.name ? scan.name + ' ' + name : name;
      scan = scan.parent;
    }

    return name;
  },

  usage: function (str) {
    var ret;

    if (str) {
      ret = commander.Command.prototype.usage.call(this, str);
    } else {
      ret = commander.Command.prototype.usage.call(this);
      ret = ret.replace(/,/g,' ');
    }

    return ret;
  },

  helpInformation: function() {
    var self = this;

    if (!self.parent) {
      var raw = self.normalize(process.argv.slice(2));
      var containsJson = raw.some(function (item) { return item === '--json'; });
      if (containsJson) {
        self.output.format({ json: true, level: 'data' });
        self.output.json(self.helpJSON());
        return '';
      }
      var packagePath = path.join(__dirname, '../../package.json');
      var packageInfo = JSON.parse(fs.readFileSync(packagePath));

      if (raw.indexOf('-v') >= 0) {
        console.log(packageInfo.version);
      } else if (raw.indexOf('--version') >= 0) {
        console.log(util.format('%s (node: %s)', packageInfo.version, process.versions.node));
      } else {
        self.setupCommandLogFormat(true);

        self.output.info('         _    _____   _ ___ ___'.cyan);
        self.output.info('        /_\\  |_  / | | | _ \\ __|'.cyan);
        self.output.info('  _ ___'.grey + '/ _ \\'.cyan + '__'.grey + '/ /| |_| |   / _|'.cyan + '___ _ _'.grey);
        self.output.info('(___  '.grey + '/_/ \\_\\/___|\\___/|_|_\\___|'.cyan + ' _____)'.grey);
        self.output.info('   (_______ _ _)         _ ______ _)_ _ '.grey);
        self.output.info('          (______________ _ )   (___ _ _)'.grey);
        self.output.info('');

        self.output.info('Microsoft Azure: Microsoft\'s Cloud Platform');
        self.output.info('');
        self.output.info('Tool version', packageInfo.version);

        self.helpCommands();
        self.helpCategoriesSummary(self.showMore());
        self.helpOptions();
        self.showCommandMode();
      }
    } else {
      self.output.help(self.description());
      self.output.help('');
      self.output.help('Usage:', self.fullName() + ' ' + self.usage());
      self.helpOptions();
      self.showCommandMode();
    }

    return '';
  },

  showMoveToNewCli: function() {
    this.output.help('');
    this.output.help('Consider Azure CLI 2.0, the preferred choice for ARM - https://aka.ms/move2cli2');
  },
  showCommandMode: function(){
    this.output.help('');
    var mode = this._mode;
    if (!mode) {
      mode = utilsCore.getMode();
    }
    var text = util.format('Current Mode: %s (Azure %s Management)', mode, 
      (mode === Constants.API_VERSIONS.ASM ? 'Service' : 'Resource')); 
    this.output.help(text);
    if (mode === Constants.API_VERSIONS.ARM) {
      this.showMoveToNewCli();
    }
  },
{'fraction_non_alphanumeric': 0.17155951938560635, 'fraction_numerical': 0.0024773937817416077, 'mean_word_length': 2.5868502887605507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6510546', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2410, 'n_words': 577}