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

'use strict';

const yargs = require('yargs');
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const ora = require('ora');

const {
  getFileNames,
  moveUsingFormatsConfig,
  moveSpecificFileTypes
} = require('./helpers');

const argv = yargs
  .usage('Usage: $0 [options]')
  .alias('o', 'output')
    .describe('o', "Output directory - Creates one if doesn't exist")
    .string('o')
  .alias('s', 'source')
    .describe('s', 'Source directory to organize')
    .string('s')
  .alias('t', 'type')
    .describe('t', 'Specific types to organize - comma separated string of file extensions')
    .string('t')
  .alias('f', 'folder')
    .describe('f', 'Specific folder to move specific files to')
    .string('f')
  .example('$0 -s ~/Downloads -o . -t "mp3, wav" -f "Songs"')
  .help('h')
  .alias('h', 'help')
  .argv;

if (!argv.source) {
  console.log(chalk.cyan('Please provide a source, do a `organize -h` for help'));
  process.exit(-1);
}

let spinner = ora('Scanning').start();

const sourceDir = argv.source ? path.resolve(
  process.cwd(), argv.source) : process.cwd();
let outputDir = argv.output ? path.resolve(
  process.cwd(), argv.output) : sourceDir;

let names = getFileNames(sourceDir);
let moved = [];

if (argv.t && argv.f) {
  const spFormats = argv.t.split(',').map(ext => ext.trim());
  const spFolder = argv.f;

  moved = moveSpecificFileTypes(spFormats, spFolder, names, sourceDir, outputDir, spinner);
} else {
  moved = moveUsingFormatsConfig(names, sourceDir, outputDir, spinner);
}

Promise.all(moved.map(p => p.catch(e => e)))<commit_msg>Forces providing source, the yargs way<commit_after>#!/usr/bin/env node

'use strict';

const yargs = require('yargs');
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const ora = require('ora');

const {
  getFileNames,
  moveUsingFormatsConfig,
  moveSpecificFileTypes
} = require('./helpers');

const argv = yargs
  .usage('Usage: $0 [options]')
  .alias('o', 'output')
    .describe('o', "Output directory - Creates one if doesn't exist")
    .string('o')
  .alias('s', 'source')
    .describe('s', 'Source directory to organize')
    .string('s')
  .alias('t', 'type')
    .describe('t', 'Specific types to organize - comma separated string of file extensions')
    .string('t')
  .alias('f', 'folder')
    .describe('f', 'Specific folder to move specific files to')
    .string('f')
  .demandOption(['s'], 'Please provide a source folder to organize')
  .example('$0 -s ~/Downloads -o . -t "mp3, wav" -f "Songs"')
  .help('h')
  .alias('h', 'help')
  .argv;

let spinner = ora('Scanning').start();

const sourceDir = argv.source ? path.resolve(
  process.cwd(), argv.source) : process.cwd();
let outputDir = argv.output ? path.resolve(
  process.cwd(), argv.output) : sourceDir;

let names = getFileNames(sourceDir);
let moved = [];

if (argv.t && argv.f) {
  const spFormats = argv.t.split(',').map(ext => ext.trim());
  const spFolder = argv.f;

  moved = moveSpecificFileTypes(spFormats, spFolder, names, sourceDir, outputDir, spinner);
} else {
  moved = moveUsingFormatsConfig(names, sourceDir, outputDir, spinner);
}

Promise.all(moved.map(p => p.catch(e => e)))
{'fraction_non_alphanumeric': 0.18742331288343558, 'fraction_numerical': 0.002147239263803681, 'mean_word_length': 4.135433070866141, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2034115', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1112, 'n_words': 295}