<commit_before>var yargs = require( 'yargs' )
var package = require( '../package' )
var log = require( 'debug' )( 'ZEUGBERG:MAIN' )
var gui = window.require( 'nw.gui' )
var Zeugberg = require( './zeugberg' )

// Patch nw.js' console.*() for nice output
require( './console' )()

// Brutally exit() on uncaught errors
process.on( 'uncaughtException', function( error ) {
  var msg = error.stack || error.message
  process.stderr.write( '\n' )
  process.stderr.write( msg )
  process.stderr.write( '\n\n' )
  process.exit( 1 )
})

process.on( 'SIGINT', function() {
  log( 'SIGINT' )
  global.zeugberg && global.zeugberg.abort( function() {
    // TODO: Stall 'til abort completed
  })
})

yargs
  .usage( 'Usage: zeugberg [options]' )
  .help( 'help' )
  .version( package.version )
  .option( 'pattern', {
    alias: 'p',
    demand: false,
    default: 'test/**/*.js',
    describe: 'Test glob pattern',
    type: 'string',
  })
  .option( 'reporter', {
    alias: 'r',
    demand: false,
    describe: 'Test reporters to use (can be specified multiple times)',
    default: 'tap',
    type: 'array',
    nargs: 1,
  })
  .option( 'debug', {
    default: false,
    describe: 'Enable debugging output',
    type: 'boolean',
  })
  .alias({
    help: 'h',
    version: 'v',
  })

// process.on( 'SIGTERM', function() {})
// process.on( 'SIGHUP', function() {})
// process.on( 'exit', function( code, signal ) {})

// Change cwd to first argv supplied
// (necessary, because nw handles arguments differently)
process.chdir( gui.App.argv.shift() )

global.argv = yargs.parse( gui.App.argv )

global.main = gui.Window.get()

// Only init main window devtools in debug mode,
// to avoid unnecessary overhead
if( global.argv.debug ) {
  global.devTools = main.showDevTools()
  global.devTools.show()
}

global.zeugberg = new Zeugberg( global.argv )

global.main.once( 'loaded', function() {
  log( 'LOADED' )
  log( 'START', process.cwd() )
  zeugberg.load( argv.pattern, function( error ) {
    zeugberg.run( function( failures ) {
      log( 'DONE', 'with ' + ( failures || 0 ) + ' failures' )
      process.exit( failures || 0 )
    })
  })
})<commit_msg>Updated lib/main: Don't exit when in DEBUG<commit_after>var yargs = require( 'yargs' )
var package = require( '../package' )
var log = require( 'debug' )( 'ZEUGBERG:MAIN' )
var gui = window.require( 'nw.gui' )
var Zeugberg = require( './zeugberg' )

// Patch nw.js' console.*() for nice output
require( './console' )()

// Brutally exit() on uncaught errors
process.on( 'uncaughtException', function( error ) {
  var msg = error.stack || error.message
  process.stderr.write( '\n' )
  process.stderr.write( msg )
  process.stderr.write( '\n\n' )
  process.exit( 1 )
})

process.on( 'SIGINT', function() {
  log( 'SIGINT' )
  global.zeugberg && global.zeugberg.abort( function() {
    // TODO: Stall 'til abort completed
  })
})

yargs
  .usage( 'Usage: zeugberg [options]' )
  .help( 'help' )
  .version( package.version )
  .option( 'pattern', {
    alias: 'p',
    demand: false,
    default: 'test/**/*.js',
    describe: 'Test glob pattern',
    type: 'string',
  })
  .option( 'reporter', {
    alias: 'r',
    demand: false,
    describe: 'Test reporters to use (can be specified multiple times)',
    default: 'tap',
    type: 'array',
    nargs: 1,
  })
  .option( 'debug', {
    default: false,
    describe: 'Enable debugging output',
    type: 'boolean',
  })
  .alias({
    help: 'h',
    version: 'v',
  })

// process.on( 'SIGTERM', function() {})
// process.on( 'SIGHUP', function() {})
// process.on( 'exit', function( code, signal ) {})

// Change cwd to first argv supplied
// (necessary, because nw handles arguments differently)
process.chdir( gui.App.argv.shift() )

global.argv = yargs.parse( gui.App.argv )

global.main = gui.Window.get()

// Only init main window devtools in debug mode,
// to avoid unnecessary overhead
if( global.argv.debug ) {
  global.devTools = main.showDevTools()
  global.devTools.show()
}

global.zeugberg = new Zeugberg( global.argv )

global.main.once( 'loaded', function() {
  log( 'LOADED' )
  log( 'START', process.cwd() )
  zeugberg.load( argv.pattern, function( error ) {
    zeugberg.run( function( failures ) {
      log( 'DONE', 'with ' + ( failures || 0 ) + ' failures' )
      // Don't exit when in DEBUG, to enable inspection
      if( !argv.debug ) {
        process.exit( failures || 0 )
      }
    })
  })
})
{'fraction_non_alphanumeric': 0.17686921165574881, 'fraction_numerical': 0.0018070928393946238, 'mean_word_length': 3.1190697674418604, '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': '1485898', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1528, 'n_words': 412}