<commit_before>const process = require('process');
const path = require('path');

// 3th lib
const program = require('commander');
const co = require('co');

const pkg = require(path.join(__dirname, '../package.json'));
const config = require('./config');

function bootstrapWrapper(func) {
  return function () {
    program.__bootstrap__ = true;
    func.apply(this, arguments);
  }
}

function errorHandler(err) {
  if (err) {
    console.error(err);
  }
  process.exit(1);
}

process.on('unhandledRejection', errorHandler);

process.on('uncaughtException', errorHandler);

process.on('warning', (warning) => {
  console.warn(warning.name);    // Print the warning name
  console.warn(warning.message); // Print the warning message
  console.warn(warning.stack);   // Print the stack trace
});

program
  .version(pkg.version)
  .description(pkg.description)
  .usage('<command> [options]');

program
  .command('add <repo>')
  .alias('a')
  .description('add a repository to gpm')
  .option("-f, --force", "forced add, ignore the question witch ask you replace the old repository or not.")
  .option("-n, --name <name>", "custom repository directory name")
  .action(bootstrapWrapper(function (repo, options) {
    co(require('./command/add')(repo, options))
      .catch(errorHandler);
  }));

program
  .command('remove [key]')
  .alias('rm')
  .description('Remove a repository from registry and disk, optional [key] to filter')
  .action(bootstrapWrapper(function (key, options) {
    co(require('./command/remove')(key, options))
      .catch(errorHandler);
  }));

program
  .command('list [key]')
  .alias('ls')
  .description('Display the all repositories in registry')
  .action(bootstrapWrapper(function (key, options) {
    co(require('./command/list')(key, options))
      .catch(errorHandler);
  }));

program
  .command('clean')
  .alias('cl')
  .description('Clear the cache, usually is ' + config.paths.temp)
  .action(bootstrapWrapper(function (options) {
    co(require('./command/clean')(options))
      .catch(errorHandler);
  }));

program
  .command('search <key>')
  .alias('sr')
  .description('@Deprecated, Search repository by a key, You can get all about the repository info')
  .action(bootstrapWrapper(function (key, options) {
    process.stderr.write('WARNING'.yellow + ':search <key> has beem @Deprecated, Please use find <key> instead. it will be remove in next major version\n');
    co(require('./command/search')(key, options)).catch(errorHandler);
  }));

program
  .command('find <key>')
  .alias('fd')
  .description('Find repository by a key, You can get all about the repository info')
  .action(bootstrapWrapper(function (key, options) {
    co(require('./command/search')(key, options)).catch(errorHandler);
  }));

program
  .command('relink')
  .alias('rl')
  .description('Relink the base directory and gpm registry, like Angular, trigger the $digest in manual')
  .option("-q, --quiet", "quiet mode, will not print any thing")
  .action(bootstrapWrapper(function (key, options) {
    co(require('./command/relink')(key, options))
      .catch(errorHandler);
  }));

program
  .command('config <action> [key] [value]')
  .alias('cf')
  .description('Config　handler, <list|get|set|delete|reset> [key] [value]')
  .action(bootstrapWrapper(function (action, key, value, options) {
    co(require('./command/config')(action, key, value, options))
      .catch(errorHandler);
  }));

program
  .command('runtime')
  .alias('rt')
  .description('Print the program runtime, useful for submit issue')
  .action(bootstrapWrapper(function (options) {
    co(require('./command/runtime')(options))
      .catch(errorHandler);
  }));

program
  .command('import <dir>')
  .alias('ip')
  .description('Import local repository into gpm registry')
  .option("--hard", "hard mode, move the repository directory to gpm base directory instead of link directory by default.")
  .option("--all", "traverse the cwd, find the child dir and import then all to gpm. loop 1 deep dir")
  .option("-f, --force", "forced mode, that mean you don't care the replace the old dir or not, just do it.")
  .option("-f, --force", "forced mode, skip the question that ask you cover the old one or not if the repository has exist in gpm registry")
  .action(bootstrapWrapper(function (dir, options) {
    co(require('./command/import')(dir, options))
      .catch(errorHandler);
  }));<commit_msg>refactor: remove duplicate option<commit_after>const process = require('process');
const path = require('path');

// 3th lib
const program = require('commander');
const co = require('co');

const pkg = require(path.join(__dirname, '../package.json'));
const config = require('./config');

function bootstrapWrapper(func) {
  return function () {
    program.__bootstrap__ = true;
    func.apply(this, arguments);
  }
}

function errorHandler(err) {
  if (err) {
    console.error(err);
  }
  process.exit(1);
}

process.on('unhandledRejection', errorHandler);

process.on('uncaughtException', errorHandler);

process.on('warning', (warning) => {
  console.warn(warning.name);    // Print the warning name
  console.warn(warning.message); // Print the warning message
  console.warn(warning.stack);   // Print the stack trace
});

program
  .version(pkg.version)
  .description(pkg.description)
  .usage('<command> [options]');

program
  .command('add <repo>')
  .alias('a')
  .description('add a repository to gpm')
  .option("-f, --force", "forced add, ignore the question witch ask you replace the old repository or not.")
  .option("-n, --name <name>", "custom repository directory name")
  .action(bootstrapWrapper(function (repo, options) {
    co(require('./command/add')(repo, options))
      .catch(errorHandler);
  }));

program
  .command('remove [key]')
  .alias('rm')
  .description('Remove a repository from registry and disk, optional [key] to filter')
  .action(bootstrapWrapper(function (key, options) {
    co(require('./command/remove')(key, options))
      .catch(errorHandler);
  }));

program
  .command('list [key]')
  .alias('ls')
  .description('Display the all repositories in registry')
  .action(bootstrapWrapper(function (key, options) {
    co(require('./command/list')(key, options))
      .catch(errorHandler);
  }));

program
  .command('clean')
  .alias('cl')
  .description('Clear the cache, usually is ' + config.paths.temp)
  .action(bootstrapWrapper(function (options) {
    co(require('./command/clean')(options))
      .catch(errorHandler);
  }));

program
  .command('search <key>')
  .alias('sr')
  .description('@Deprecated, Search repository by a key, You can get all about the repository info')
  .action(bootstrapWrapper(function (key, options) {
    process.stderr.write('WARNING'.yellow + ':search <key> has beem @Deprecated, Please use find <key> instead. it will be remove in next major version\n');
    co(require('./command/search')(key, options)).catch(errorHandler);
  }));

program
  .command('find <key>')
  .alias('fd')
  .description('Find repository by a key, You can get all about the repository info')
  .action(bootstrapWrapper(function (key, options) {
    co(require('./command/search')(key, options)).catch(errorHandler);
  }));

program
  .command('relink')
  .alias('rl')
  .description('Relink the base directory and gpm registry, like Angular, trigger the $digest in manual')
  .option("-q, --quiet", "quiet mode, will not print any thing")
  .action(bootstrapWrapper(function (key, options) {
    co(require('./command/relink')(key, options))
      .catch(errorHandler);
  }));

program
  .command('config <action> [key] [value]')
  .alias('cf')
  .description('Config　handler, <list|get|set|delete|reset> [key] [value]')
  .action(bootstrapWrapper(function (action, key, value, options) {
    co(require('./command/config')(action, key, value, options))
      .catch(errorHandler);
  }));

program
  .command('runtime')
  .alias('rt')
  .description('Print the program runtime, useful for submit issue')
  .action(bootstrapWrapper(function (options) {
    co(require('./command/runtime')(options))
      .catch(errorHandler);
  }));

program
  .command('import <dir>')
  .alias('ip')
  .description('Import local repository into gpm registry')
  .option("--hard", "hard mode, move the repository directory to gpm base directory instead of link directory by default.")
  .option("--all", "traverse the cwd, find the child dir and import then all to gpm. loop 1 deep dir")
  .option("-f, --force", "forced mode, skip the question that ask you cover the old one or not if the repository has exist in gpm registry")
  .action(bootstrapWrapper(function (dir, options) {
    co(require('./command/import')(dir, options))
      .catch(errorHandler);
  }));
{'fraction_non_alphanumeric': 0.16483390607101947, 'fraction_numerical': 0.0006872852233676976, 'mean_word_length': 4.3108272506082725, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '4374781', 'n_tokens_mistral': 2591, 'n_tokens_neox': 2590, 'n_words': 734}