<commit_before>#!/usr/bin/env node

var subcommand = require('subcommand')
var usage = require('../lib/usage')

process.title = 'dat-next'

var config = {
  defaults: [
    { name: 'dir', default: process.cwd() },
    { name: 'logspeed', default: 200 },
    { name: 'port', default: 3282 },
    { name: 'utp', default: true, boolean: true },
    { name: 'debug', default: process.env.DEBUG },
    { name: 'quiet', default: false, boolean: true },
    { name: 'verbose', default: false, boolean: true, abbr: 'v' },
    { name: 'server', default: 'https://dat.land/api/v1' }
  ],
  root: {
    options: [
      {
        name: 'version',
        boolean: true,
        default: false,
        abbr: 'v'
      }
    ],
    command: usage
  },
  none: syncShorthand,
  commands: [
    require('../lib/commands/clone'),
    require('../lib/commands/create'),
    require('../lib/commands/doctor'),
    require('../lib/commands/publish'),
    require('../lib/commands/pull'),
    require('../lib/commands/snapshot'),
    require('../lib/commands/sync'),
    require('../lib/commands/auth/register'),
    require('../lib/commands/auth/whoami'),
    require('../lib/commands/auth/logout'),
    require('../lib/commands/auth/login'),
    {
      name: 'help',
      command: usage
    }
  ],
  aliases: {
    'init': 'create'
  }
}

var match = subcommand(config)
match(alias(process.argv.slice(2)))

function alias (argv) {
  var cmd = argv[0]
  if (!config.aliases[cmd]) return argv
  argv[0] = config.aliases[cmd]
  return argv
}

function syncShorthand (opts) {
  if (!opts._.length) return usage(opts)
  opts.dir = opts._[0]
  var sync = require('../lib/commands/sync')
  opts.import = opts.import || true // TODO: use default opts in sync
  sync.command(opts)
}<commit_msg>fix bad commands by checking dir<commit_after>#!/usr/bin/env node

var subcommand = require('subcommand')
var fs = require('fs')
var usage = require('../lib/usage')

process.title = 'dat-next'

var config = {
  defaults: [
    { name: 'dir', default: process.cwd() },
    { name: 'logspeed', default: 200 },
    { name: 'port', default: 3282 },
    { name: 'utp', default: true, boolean: true },
    { name: 'debug', default: process.env.DEBUG },
    { name: 'quiet', default: false, boolean: true },
    { name: 'verbose', default: false, boolean: true, abbr: 'v' },
    { name: 'server', default: 'https://dat.land/api/v1' }
  ],
  root: {
    options: [
      {
        name: 'version',
        boolean: true,
        default: false,
        abbr: 'v'
      }
    ],
    command: usage
  },
  none: syncShorthand,
  commands: [
    require('../lib/commands/clone'),
    require('../lib/commands/create'),
    require('../lib/commands/doctor'),
    require('../lib/commands/publish'),
    require('../lib/commands/pull'),
    require('../lib/commands/snapshot'),
    require('../lib/commands/sync'),
    require('../lib/commands/auth/register'),
    require('../lib/commands/auth/whoami'),
    require('../lib/commands/auth/logout'),
    require('../lib/commands/auth/login'),
    {
      name: 'help',
      command: usage
    }
  ],
  aliases: {
    'init': 'create'
  }
}

var match = subcommand(config)
match(alias(process.argv.slice(2)))

function alias (argv) {
  var cmd = argv[0]
  if (!config.aliases[cmd]) return argv
  argv[0] = config.aliases[cmd]
  return argv
}

function syncShorthand (opts) {
  if (!opts._.length) return usage(opts)
  try {
    opts.dir = opts._[0]
    fs.stat(opts.dir, function (err, stat) {
      if (err || !stat.isDirectory()) return usage(opts)

      var sync = require('../lib/commands/sync')
      opts.import = opts.import || true // TODO: use default opts in sync
      sync.command(opts)
    })
  } catch (e) {
    return usage(opts)
  }
}
{'fraction_non_alphanumeric': 0.19190843758317808, 'fraction_numerical': 0.006388075592227841, 'mean_word_length': 2.7467597208374874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3452079', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1259, 'n_words': 274}