<commit_before>program = require 'commander'
log = require 'loggo'
async = require 'async'
shake = require '../index'
{join} = require 'path'

log.setName 'shake'
package = require join __dirname, '../package.json'

getShakeFile = ->
  # Find shake file
  try
    shakeFile = require.resolve join process.cwd(), '.shake'
  catch e
    return log.error ".shake not found!"
  shakeConfig = require shakeFile
  return log.error "Missing target in .shake" if typeof shakeConfig.target isnt 'string'
  return shakeConfig

module.exports =
  run: (argv) ->
    program
      .version(package.version)
      .usage '<tasks>'

    program.command('*')
      .description('Execute tasks')
      .action (tasks, mode) ->
        shakeConfig = getShakeFile()
        return unless shakeConfig
        if tasks is 'list'
          log.info "Available tasks:"
          log.info "--". key for key, val of shakeConfig when typeof val is 'function'
        else
          tasks = tasks.split ':'
          log.info "Target: #{shakeConfig.target}"
          remote = shake.getRemote shakeConfig.target
          local = shake.getLocal process.cwd()

          runTask = (task, cb) ->
            log.info "Executing '#{task}'..."
            taskFn = shakeConfig[task]
            return log.error "'#{task}' does not exist" if typeof taskFn isnt 'function'
            taskFn local, remote, (err, res) ->
              log.error err if err?
              log.info res if res?
              cb err, res

          async.mapSeries tasks, runTask, (err, res) -> log.info "Tasks completed!"

    program.parse argv<commit_msg>better tasks listing<commit_after>program = require 'commander'
log = require 'loggo'
async = require 'async'
shake = require '../index'
{join} = require 'path'

log.setName 'shake'
package = require join __dirname, '../package.json'

getShakeFile = ->
  # Find shake file
  try
    shakeFile = require.resolve join process.cwd(), '.shake'
  catch e
    return log.error ".shake not found!"
  shakeConfig = require shakeFile
  return log.error "Missing target in .shake" if typeof shakeConfig.target isnt 'string'
  return shakeConfig

shakeConfig = getShakeFile()

module.exports =
  run: (argv) ->
    return unless shakeConfig
    program
      .version(package.version)
      .usage('<tasks>')
      .option '-t, --tasks', 'list tests'

    program.command('*')
      .description('Execute tasks')
      .action (tasks, mode) ->
        tasks = tasks.split ':'
        log.info "Target: #{shakeConfig.target}"
        remote = shake.getRemote shakeConfig.target
        local = shake.getLocal process.cwd()

        runTask = (task, cb) ->
          log.info "Executing '#{task}'..."
          taskFn = shakeConfig[task]
          return log.error "'#{task}' does not exist" if typeof taskFn isnt 'function'
          taskFn local, remote, (err, res) ->
            log.error err if err?
            log.info res if res?
            cb err, res

        async.mapSeries tasks, runTask, (err, res) -> log.info "Tasks completed!"

    program.parse argv

    if program.tasks
      log.info "Available tasks:"
      log.info "--". key for key, val of shakeConfig when typeof val is 'function'
{'fraction_non_alphanumeric': 0.12027491408934708, 'fraction_numerical': 0.0, 'mean_word_length': 2.402763018065887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '7204270', 'n_tokens_mistral': 911, 'n_tokens_neox': 902, 'n_words': 300}