<commit_before>require 'coffee-script/register'

path = require 'path'
yargs = require 'yargs'
Abao = require '../lib/abao'
pkg = require '../package'

showReporters = () ->
  # Copied from node_modules/mocha/_mocha
  console.log()
  console.log '    dot - dot matrix'
  console.log '    doc - html documentation'
  console.log '    spec - hierarchical spec list'
  console.log '    json - single json object'
  console.log '    progress - progress bar'
  console.log '    list - spec-style listing'
  console.log '    tap - test-anything-protocol'
  console.log '    landing - unicode landing strip'
  console.log '    xunit - xunit reporter'
  console.log '    min - minimal reporter (great with --watch)'
  console.log '    json-stream - newline delimited json events'
  console.log '    markdown - markdown documentation (github flavour)'
  console.log '    nyan - nyan cat!'
  console.log()
  return

binary = path.basename pkg.bin

argv = yargs
  .usage('Usage:\n  ' + binary + ' </path/to/raml> [OPTIONS]' +
    '\n\nExample:\n  ' + binary + ' api.raml --server http://api.example.com')
  .options(Abao.options)
  .implies('template', 'generate-hooks')
  .check((argv) ->
    if argv.reporters == true
      showReporters()
      process.exit 0

    if argv._.length < 1
      throw new Error binary + ': must specify path to RAML file'
    else if argv._.length > 1
      throw new Error binary + ': accepts single positional command-line argument'

    return true
  )
  .wrap(80)
  .help('help', 'Show usage information and exit')
  .version().describe('version', 'Show version number and exit')
  .epilog('Website:\n  ' + pkg.homepage)
  .argv

configuration =
  'ramlPath': argv._[0],
  'options':  argv

abao = new Abao configuration

abao.run (error, nfailures) ->
  if error
    if error.message
      console.error error.message
    if error.stack
      console.error error.stack
    process.exit 1

  process.exit (if nfailures > 0 then 1 else 0)

<commit_msg>Make exit handling more explicit.<commit_after>require 'coffee-script/register'

path = require 'path'
yargs = require 'yargs'
Abao = require '../lib/abao'
pkg = require '../package'

EXIT_SUCCESS = 0
EXIT_FAILURE = 1

showReporters = () ->
  # Copied from node_modules/mocha/_mocha
  console.log()
  console.log '    dot - dot matrix'
  console.log '    doc - html documentation'
  console.log '    spec - hierarchical spec list'
  console.log '    json - single json object'
  console.log '    progress - progress bar'
  console.log '    list - spec-style listing'
  console.log '    tap - test-anything-protocol'
  console.log '    landing - unicode landing strip'
  console.log '    xunit - xunit reporter'
  console.log '    min - minimal reporter (great with --watch)'
  console.log '    json-stream - newline delimited json events'
  console.log '    markdown - markdown documentation (github flavour)'
  console.log '    nyan - nyan cat!'
  console.log()
  return

binary = path.basename pkg.bin

argv = yargs
  .usage('Usage:\n  ' + binary + ' </path/to/raml> [OPTIONS]' +
    '\n\nExample:\n  ' + binary + ' api.raml --server http://api.example.com')
  .options(Abao.options)
  .implies('template', 'generate-hooks')
  .check((argv) ->
    if argv.reporters == true
      showReporters()
      process.exit EXIT_SUCCESS

    # Ensure single positional argument present
    if argv._.length < 1
      throw new Error binary + ': must specify path to RAML file'
    else if argv._.length > 1
      throw new Error binary + ': accepts single positional command-line argument'

    return true
  )
  .wrap(80)
  .help('help', 'Show usage information and exit')
  .version().describe('version', 'Show version number and exit')
  .epilog('Website:\n  ' + pkg.homepage)
  .argv

configuration =
  'ramlPath': argv._[0],
  'options':  argv

abao = new Abao configuration

abao.run (error, nfailures) ->
  if error
    process.exitCode = EXIT_FAILURE
    if error.message
      console.error error.message
    if error.stack
      console.error error.stack

  if nfailures > 0
    process.exitCode = EXIT_FAILURE

  process.exit()


{'fraction_non_alphanumeric': 0.12141119221411192, 'fraction_numerical': 0.004379562043795621, 'mean_word_length': 2.831314072693383, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '2075764', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1286, 'n_words': 375}