<commit_before>import path from 'path'
import program from 'commander'
import sagui, { MissingPackageJSON, SaguiPath } from '../index'
import buildTargets from '../build-targets'
import { logError, logWarning } from '../util/log'

/**
 * Command line interface for Sagui
 */
export default (argv = []) => {
  try {
    program.parse(argv)
  } catch (e) {
    if (e instanceof SaguiPath || e instanceof MissingPackageJSON) {
      logWarning(e.message)
      return
    }

    logError('Error starting up')
    logError(e.stack || e)
  }

  if (!argv.slice(2).length) program.outputHelp()
}

const setupAction = (action) => (cliOptions = {}) => {
  const options = {
    ...cliOptions,
    action,
    buildTarget: normalize(process.env.NODE_ENV),
    projectPath: process.env.SAGUI_LINK
      ? process.cwd()
      : path.join(__dirname, '../../../../')
  }

  sagui(options).run()
}

const normalize = (env = buildTargets.DEVELOPMENT) => env.toLowerCase().trim()

program.command('install')
  .description('Install or update sagui in the current project')
  .action(setupAction('install'))

program.command('test')
  .description('Run tests')
  .option('-w, --watch', 'Run tests on any file change')
  .action(setupAction('test'))

program.command('build')
  .description('Build the project')<commit_msg>Add missing ‘coverage’ flag to test cli action 👀<commit_after>import path from 'path'
import program from 'commander'
import sagui, { MissingPackageJSON, SaguiPath } from '../index'
import buildTargets from '../build-targets'
import { logError, logWarning } from '../util/log'

/**
 * Command line interface for Sagui
 */
export default (argv = []) => {
  try {
    program.parse(argv)
  } catch (e) {
    if (e instanceof SaguiPath || e instanceof MissingPackageJSON) {
      logWarning(e.message)
      return
    }

    logError('Error starting up')
    logError(e.stack || e)
  }

  if (!argv.slice(2).length) program.outputHelp()
}

const setupAction = (action) => (cliOptions = {}) => {
  const options = {
    ...cliOptions,
    action,
    buildTarget: normalize(process.env.NODE_ENV),
    projectPath: process.env.SAGUI_LINK
      ? process.cwd()
      : path.join(__dirname, '../../../../')
  }

  sagui(options).run()
}

const normalize = (env = buildTargets.DEVELOPMENT) => env.toLowerCase().trim()

program.command('install')
  .description('Install or update sagui in the current project')
  .action(setupAction('install'))

program.command('test')
  .description('Run tests')
  .option('-w, --watch', 'Run tests on any file change')
  .option('-c, --coverage', 'Generate a coverage report')
  .action(setupAction('test'))

program.command('build')
  .description('Build the project')
{'fraction_non_alphanumeric': 0.1616722160562338, 'fraction_numerical': 0.0007399186089530152, 'mean_word_length': 3.559865092748735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1599741', 'n_tokens_mistral': 852, 'n_tokens_neox': 838, 'n_words': 209}