<commit_before>path = require 'path'
fs = require 'fs'
_ = require 'underscore'
async = require 'async'
mkdirp = require 'mkdirp'
fsUtils = require 'fs-utils'

symlinkCommand = (sourcePath, destinationPath, callback) ->
  mkdirp path.dirname(destinationPath), (error) ->
    if error?
      callback(error)
    else
      fs.symlink sourcePath, destinationPath, (error) ->
        if error?
          callback(error)
        else
          fs.chmod(destinationPath, 0o755, callback)

unlinkCommand = (destinationPath, callback) ->
  fs.unlink destinationPath, (error) ->
    if error? and error.code isnt 'ENOENT'
      callback(error)
    else
      callback()

module.exports =
  findInstallDirectory: (callback) ->
    directories = ['/opt/boxen','/opt/github','/usr/local']
    async.detect(directories, fsUtils.isDirectory, callback)

  install: (commandPath, commandName, callback) ->
    if not commandName? or _.isFunction(commandName)
      callback = commandName
      commandName = path.basename(commandPath, path.extname(commandPath))

    installCallback = (error) ->
      if error?
        console.warn "Failed to install `#{commandName}` binary", error
      callback?(error)

    @findInstallDirectory (directory) ->
      if directory?
        destinationPath = path.join(directory, 'bin', commandName)
        unlinkCommand destinationPath, (error) ->
          if error?
            installCallback(error)
          else
            symlinkCommand(commandPath, destinationPath, installCallback)
      else
        installCallback(new Error("No destination directory exists to install"))<commit_msg>:lipstick: space separate array items<commit_after>path = require 'path'
fs = require 'fs'
_ = require 'underscore'
async = require 'async'
mkdirp = require 'mkdirp'
fsUtils = require 'fs-utils'

symlinkCommand = (sourcePath, destinationPath, callback) ->
  mkdirp path.dirname(destinationPath), (error) ->
    if error?
      callback(error)
    else
      fs.symlink sourcePath, destinationPath, (error) ->
        if error?
          callback(error)
        else
          fs.chmod(destinationPath, 0o755, callback)

unlinkCommand = (destinationPath, callback) ->
  fs.unlink destinationPath, (error) ->
    if error? and error.code isnt 'ENOENT'
      callback(error)
    else
      callback()

module.exports =
  findInstallDirectory: (callback) ->
    directories = ['/opt/boxen', '/opt/github', '/usr/local']
    async.detect(directories, fsUtils.isDirectory, callback)

  install: (commandPath, commandName, callback) ->
    if not commandName? or _.isFunction(commandName)
      callback = commandName
      commandName = path.basename(commandPath, path.extname(commandPath))

    installCallback = (error) ->
      if error?
        console.warn "Failed to install `#{commandName}` binary", error
      callback?(error)

    @findInstallDirectory (directory) ->
      if directory?
        destinationPath = path.join(directory, 'bin', commandName)
        unlinkCommand destinationPath, (error) ->
          if error?
            installCallback(error)
          else
            symlinkCommand(commandPath, destinationPath, installCallback)
      else
        installCallback(new Error("No destination directory exists to install"))
{'fraction_non_alphanumeric': 0.1079092581238504, 'fraction_numerical': 0.002452483139178418, 'mean_word_length': 3.1461245235069883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '3839587', 'n_tokens_mistral': 908, 'n_tokens_neox': 892, 'n_words': 233}