<commit_before>#!/usr/bin/env node
// native
const path = require('path')

// packages
const moment = require('moment')
const prog = require('caporal')
const jsonfile = require('jsonfile')

// ours
const db = require('./storage.js')
const helpers = require('./utils/helpers.js')

// constants

const TODAY = moment().format('YYYY-MM-DD')
const VERSION = require('./package.json').version
const CONFIG_FILE = path.join(__dirname, 'config.json')
const CONFIG = jsonfile.readFileSync(CONFIG_FILE)

const setConfig = (args, options, logger) => {
  if (options.day) {
    CONFIG.HOURS_IN_A_WORK_DAY = options.day
  }

  if (options.break) {
    CONFIG.BREAK_DEFAULT = options.break
  }
  jsonfile.writeFileSync(CONFIG_FILE, CONFIG)
  console.log(CONFIG)
  process.exit(0)
}
// set end of the work day
const setEnd = (args, options, logger) => {
  const end = args.end || moment().format('HH:mm')
  logger.info('Your end of the day registered as: ', end)

  db
    .updateDatabase(TODAY, null, end, CONFIG.BREAK_DEFAULT, 'setEnd')
    .then(() => { report() })
}

// to tell users when they can go home!
const shouldWorkUntil = (start, logger) => {
  const goHomeTime = helpers.composeDateObject(start)
    .add({hour: CONFIG.HOURS_IN_A_WORK_DAY})
    .add({minutes: CONFIG.BREAK_DEFAULT})
    .format('HH:mm')
  logger.info('\n Working until ', goHomeTime, `will make it a full (${CONFIG.HOURS_IN_A_WORK_DAY}) day`)
}

const setStart = (args, options, logger) => {
  const start = args.start || moment().format('HH:mm')
  logger.info('\n Your start of the day registered as ', start)

  shouldWorkUntil(start, logger)

  // update database
  db
    .updateDatabase(TODAY, start, null, CONFIG.BREAK_DEFAULT, 'setStart')
    .catch((err) => { logger.error(err) })
    .finally(() => { db.destroyKnex() })

  logger.info('\n TIP: next time you run moro the end of your day will be set')
}

// set total duration of break for today
const setBreak = (args, options, logger) => {
  const duration = args.duration || CONFIG.BREAK_DEFAULT
  logger.info('Break took: ', duration, 'Minutes', ' And will be removed from your work hours')
  db.updateDatabase(TODAY, null, null, duration, 'setBreakDuration')
}

// report functionality for both single and batch reporting
const report = (args, options, logger = console.log, date = TODAY) => {
  if (options && options.all) {
    db
      .getFullReport()
      .catch((error) => { console.log(error) })
      .finally(() => { db.destroyKnex() })

    return<commit_msg>Fix not exiting after setting break duration<commit_after>#!/usr/bin/env node
// native
const path = require('path')

// packages
const moment = require('moment')
const prog = require('caporal')
const jsonfile = require('jsonfile')

// ours
const db = require('./storage.js')
const helpers = require('./utils/helpers.js')

// constants

const TODAY = moment().format('YYYY-MM-DD')
const VERSION = require('./package.json').version
const CONFIG_FILE = path.join(__dirname, 'config.json')
const CONFIG = jsonfile.readFileSync(CONFIG_FILE)

const setConfig = (args, options, logger) => {
  if (options.day) {
    CONFIG.HOURS_IN_A_WORK_DAY = options.day
  }

  if (options.break) {
    CONFIG.BREAK_DEFAULT = options.break
  }
  jsonfile.writeFileSync(CONFIG_FILE, CONFIG)
  console.log(CONFIG)
  process.exit(0)
}
// set end of the work day
const setEnd = (args, options, logger) => {
  const end = args.end || moment().format('HH:mm')
  logger.info('Your end of the day registered as: ', end)

  db
    .updateDatabase(TODAY, null, end, CONFIG.BREAK_DEFAULT, 'setEnd')
    .then(() => { report() })
}

// to tell users when they can go home!
const shouldWorkUntil = (start, logger) => {
  const goHomeTime = helpers.composeDateObject(start)
    .add({hour: CONFIG.HOURS_IN_A_WORK_DAY})
    .add({minutes: CONFIG.BREAK_DEFAULT})
    .format('HH:mm')
  logger.info('\n Working until ', goHomeTime, `will make it a full (${CONFIG.HOURS_IN_A_WORK_DAY}) day`)
}

const setStart = (args, options, logger) => {
  const start = args.start || moment().format('HH:mm')
  logger.info('\n Your start of the day registered as ', start)

  shouldWorkUntil(start, logger)

  // update database
  db.updateDatabase(TODAY, start, null, CONFIG.BREAK_DEFAULT, 'setStart')
    .catch((err) => { logger.error(err) })
    .finally(() => { db.destroyKnex() })

  logger.info('\n TIP: next time you run moro the end of your day will be set')
}

// set total duration of break for today
const setBreak = (args, options, logger) => {
  const duration = args.duration || CONFIG.BREAK_DEFAULT
  logger.info('Break took: ', duration, 'Minutes', ' And will be removed from your work hours')
  db.updateDatabase(TODAY, null, null, duration, 'setBreakDuration')
    .catch((err) => { logger.error(err) })
    .finally(() => { db.destroyKnex() })
}

// report functionality for both single and batch reporting
const report = (args, options, logger = console.log, date = TODAY) => {
  if (options && options.all) {
    db
      .getFullReport()
      .catch((error) => { console.log(error) })
      .finally(() => { db.destroyKnex() })

    return
{'fraction_non_alphanumeric': 0.15330465389127884, 'fraction_numerical': 0.00039108330074305825, 'mean_word_length': 3.8994252873563218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '1702401', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1633, 'n_words': 452}