<commit_before>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

'use strict';

var glob = require('glob'),
path = require('path'),
SpecValidator = require('./lib/specValidator'),
RefParser = require('json-schema-ref-parser'),
swt = require('swagger-tools').specs.v2,
finalValidationResult = {};

var cmd = process.argv[2];
exports.printUsage = function printUsage() {
  console.log('');
  console.log('Usage: node validate.js <command> <spec-path> [--json]\n\n');
  console.log('Commands:\n');
  console.log('  - spec <raw-github-url OR local file-path to the swagger spec> [--json]    | Description: Performs semantic validation of the spec.\n')
  console.log('  - example <raw-github-url OR local file-path to the swagger spec> [--json] | Description: Performs validation of x-ms-examples and examples present in the spec.\n')
  process.exit(1);
}

if (cmd === '-h' || cmd === '--help' || cmd === 'help') {
  exports.printUsage();
}

var specPath = process.argv[3];
var jsonOutput = process.argv[4];
if (cmd !== 'spec' && cmd !== 'example') {
  if (cmd) console.error(`${cmd} is not a valid command.`)
  exports.printUsage();
}
if (!specPath) {
  console.error(`<spec-path> (raw-github url or a local file path to the swagger spec) is required.`);
  exports.printUsage();
}

function printResult(validator) {
  if (jsonOutput && jsonOutput === '--json') {
    console.log('\n> Final Validation Result object:\n')
    console.dir(finalValidationResult, { depth: null, colors: true });
  }
  console.log('\n> Validation Complete.');
}

var validator;
if (cmd === 'example') {
  console.log(`\n> Validating "examples" and "x-ms-examples" in ${specPath}:\n`);
  validator = new SpecValidator(specPath);<commit_msg>Suggestion to change the result object message<commit_after>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

'use strict';

var glob = require('glob'),
path = require('path'),
SpecValidator = require('./lib/specValidator'),
RefParser = require('json-schema-ref-parser'),
swt = require('swagger-tools').specs.v2,
finalValidationResult = {};

var cmd = process.argv[2];
exports.printUsage = function printUsage() {
  console.log('');
  console.log('Usage: node validate.js <command> <spec-path> [--json]\n\n');
  console.log('Commands:\n');
  console.log('  - spec <raw-github-url OR local file-path to the swagger spec> [--json]    | Description: Performs semantic validation of the spec.\n')
  console.log('  - example <raw-github-url OR local file-path to the swagger spec> [--json] | Description: Performs validation of x-ms-examples and examples present in the spec.\n')
  process.exit(1);
}

if (cmd === '-h' || cmd === '--help' || cmd === 'help') {
  exports.printUsage();
}

var specPath = process.argv[3];
var jsonOutput = process.argv[4];
if (cmd !== 'spec' && cmd !== 'example') {
  if (cmd) console.error(`${cmd} is not a valid command.`)
  exports.printUsage();
}
if (!specPath) {
  console.error(`<spec-path> (raw-github url or a local file path to the swagger spec) is required.`);
  exports.printUsage();
}

function printResult(validator) {
  if (jsonOutput && jsonOutput === '--json') {
    console.log('\n> Detailed Validation Result:\n')
    console.dir(finalValidationResult, { depth: null, colors: true });
  }
  console.log('\n> Validation Complete.');
}

var validator;
if (cmd === 'example') {
  console.log(`\n> Validating "examples" and "x-ms-examples" in ${specPath}:\n`);
  validator = new SpecValidator(specPath);
{'fraction_non_alphanumeric': 0.17324979569599563, 'fraction_numerical': 0.002724053391446472, 'mean_word_length': 4.30635838150289, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '6088204', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1138, 'n_words': 344}