<commit_before>var path = require('path');
var fs = require('fs');
var feedback = require('feedback');
var print = require('pretty-print');
var _ = require('lodash');
var format = require('chalk');
var sortObject = require('sorted-object');

var help = function (cli) {
  var write = writeWithPadding();
  
  // Default help command
  var helpCommand = cli.command('help')
    .secret(true)
    .handler(function () {
      printIntro();
      printUsage('  ' + programName() + ' <command> <parameters> <options>');
      printCommands();
      printOptions();
    });
  
  helpCommand.task('detail')
    .handler(function (cmd, done) {
      var command = cli.getCommand(cmd);
      var usageStr = '';
      
      // TODO: handle parameteres and options correctly
      _.each(command._aliasesWithUsage, function (alias, idx) {
        usageStr += '  ' + programName() + ' ' + alias;
        if (idx < command._aliasesWithUsage.length - 1) usageStr += '\n  ';
      });
      
      write()
      write(format.bold(cmd) + ': ' + command._description);
      
      printUsage(usageStr);
      printTasks(command._tasks);
      printOptions();
    });

  // Default -h, --help flags
  cli.flag('-h', '--help')
    .description('display Divshot help and options')
    .exit(true)
    .handler(function () {
      cli.commands.help({debug: true});
    });
  
  function printIntro () {
    write();
    write((cli.color) ? format[cli.color](cli.title) : cli.title);
    write()
    write((cli.color) ? format[cli.color](cli.description) : cli.description);
  }

  function printUsage (commandUsage) {
    write();
    write((cli.color) ? format[cli.color]('Usage:') : 'Usage:');
    write();
    // write('  ' + programName() + ' <command> <parameters> <options>');
    write(commandUsage);
  }

  function printCommands () {
    var cmds = {};
    
    write();
    write((cli.color) ? format[cli.color]('Commands:') : 'Commands:');
    write();
    
    _.each(sortObject(cli._commandsWithCombinedAlias), function (cmd, key) {
      var cliCommand = cli._commandsWithCombinedAlias[key];
    
      // Only show commands that aren't set to hide
      if (!cliCommand._secret) cmds[key] = cliCommand._description;
    });
    
    print(cmds, {
      leftPadding: 4,
      rightPadding: 4
    });
  }
  
  function printTasks (tasks) {
    if (_.keys(tasks).length < 1) return;
    
    var taskList = {};
    var sortedTasks = sortObject(tasks);
    
    write();
    write((cli.color) ? format[cli.color]('Tasks:') : 'Tasks:');
    write();
    
    var taskList = _(sortedTasks)
      .keys()
      .map(function (key) {
        return ':' + key;
      })
      .zipObject(_(sortedTasks).map(function (task, key) {
        return task._description
      }).value()).value();
    
    print(taskList, {
      leftPadding: 4,
      rightPadding: 4
    });
  }

  function printOptions () {
    var flags = {};
    
    write();
    write((cli.color) ? format[cli.color]('Options:') : 'Options:')
    write();
    
    
    _.each(sortObject(cli._flagsWithCombinedAlias), function (cmd, key) {
      var cliFlag = cli._flagsWithCombinedAlias[key];
      if (!cliFlag._secret) flags[key] = cliFlag._description;
    });
    
    print(flags, {
      leftPadding: 4,
      rightPadding: 4
    });
  }

  function writeWithPadding() {
    return function (data) {
      cli.log('  ' + (data || ''));
    };
  }

  function programName () {
    var appDir = path.dirname(module.parent.parent.filename);
    var name = '<program>';
    
    try{
      var pkg = require(appDir + '/package.json');
      var name = Object.keys(pkg.bin)[0];
    }
    catch(e) {}
    
    return name;
  }
};

help.forCommmand = function (input) {
  var help = false;
  var command;
  
  // program command help
  if (input.command && input.args.indexOf('help') > -1) {
    command = input.command;
    help = true;
  }
  
  // program apps -h
  if (input.command && input.args.h) {
    command = input.command;
    help = true;
  }
  
  // program command --help
  if (input.command && input.args.help) {
    command = input.command;
    help = true;
  }
  
  // program help command
  // NOT program help:detail command
  if (input.command === 'help' && !input.task && input.args.length > 0) {
    command = input.args[0];
    help = true;
  }
  
  // program -h command
  if (!input.command && input.args.h && input.args.h !== true) {
    command = input.args.h;
    help = true;
  }
  
  // program --help command
  if (!input.command && input.args.help && input.args.help !== true) {
    command = input.args.help;
    help = true;
  }
  
  return (help) ? command : false;
};

module.exports = help;<commit_msg>update command usage<commit_after>var path = require('path');
var fs = require('fs');
var feedback = require('feedback');
var print = require('pretty-print');
var _ = require('lodash');
var format = require('chalk');
var sortObject = require('sorted-object');

var help = function (cli) {
  var write = writeWithPadding();
  
  // Default help command
  var helpCommand = cli.command('help')
    .secret(true)
    .handler(function () {
      printIntro();
      printUsage('  ' + programName() + ' <command> <parameters> <options>');
      printCommands();
      printOptions();
    });
  
  helpCommand.task('detail')
    .handler(function (cmd, done) {
      var command = cli.getCommand(cmd);
      var usageStr = '';
      
      // TODO: handle parameteres and options correctly
      _.each(command._aliasesWithUsage, function (alias, idx) {
        usageStr += '  ' + programName() + ' ' + alias;
        if (idx < command._aliasesWithUsage.length - 1) usageStr += '\n  ';
      });
      
      write()
      write(format.bold(cmd) + ': ' + command._description);
      
      printUsage(usageStr);
      printTasks(command._tasks);
      printOptions();
    });

  // Default -h, --help flags
  cli.flag('-h', '--help')
    .description('display Divshot help and options')
    .exit(true)
    .handler(function () {
      cli.commands.help({debug: true});
    });
  
  function printIntro () {
    write();
    write((cli.color) ? format[cli.color](cli.title) : cli.title);
    write()
    write((cli.color) ? format[cli.color](cli.description) : cli.description);
  }

  function printUsage (commandUsage) {
    write();
    write((cli.color) ? format[cli.color]('Usage:') : 'Usage:');
    write();
    write(commandUsage);
  }

  function printCommands () {
    var cmds = {};
    
    write();
    write((cli.color) ? format[cli.color]('Commands:') : 'Commands:');
    write();
    
    _.each(sortObject(cli._commandsWithCombinedAlias), function (cmd, key) {
      var cliCommand = cli._commandsWithCombinedAlias[key];
    
      // Only show commands that aren't set to hide
      if (!cliCommand._secret) cmds[key] = cliCommand._description;
    });
    
    print(cmds, {
      leftPadding: 4,
      rightPadding: 4
    });
  }
  
  function printTasks (tasks) {
    if (_.keys(tasks).length < 1) return;
    
    var taskList = {};
    var sortedTasks = sortObject(tasks);
    
    write();
    write((cli.color) ? format[cli.color]('Tasks:') : 'Tasks:');
    write();
    
    var taskList = _(sortedTasks)
      .keys()
      .map(function (key) {
        return ':' + key;
      })
      .zipObject(_(sortedTasks).map(function (task, key) {
        return task._description
      }).value()).value();
    
    print(taskList, {
      leftPadding: 4,
      rightPadding: 4
    });
  }

  function printOptions () {
    var flags = {};
    
    write();
    write((cli.color) ? format[cli.color]('Options:') : 'Options:')
    write();
    
    
    _.each(sortObject(cli._flagsWithCombinedAlias), function (cmd, key) {
      var cliFlag = cli._flagsWithCombinedAlias[key];
      if (!cliFlag._secret) flags[key] = cliFlag._description;
    });
    
    print(flags, {
      leftPadding: 4,
      rightPadding: 4
    });
  }

  function writeWithPadding() {
    return function (data) {
      cli.log('  ' + (data || ''));
    };
  }

  function programName () {
    var appDir = path.dirname(module.parent.parent.filename);
    var name = '<program>';
    
    try{
      var pkg = require(appDir + '/package.json');
      var name = Object.keys(pkg.bin)[0];
    }
    catch(e) {}
    
    return name;
  }
};

help.forCommmand = function (input) {
  var help = false;
  var command;
  
  // program command help
  if (input.command && input.args.indexOf('help') > -1) {
    command = input.command;
    help = true;
  }
  
  // program apps -h
  if (input.command && input.args.h) {
    command = input.command;
    help = true;
  }
  
  // program command --help
  if (input.command && input.args.help) {
    command = input.command;
    help = true;
  }
  
  // program help command
  // NOT program help:detail command
  if (input.command === 'help' && !input.task && input.args.length > 0) {
    command = input.args[0];
    help = true;
  }
  
  // program -h command
  if (!input.command && input.args.h && input.args.h !== true) {
    command = input.args.h;
    help = true;
  }
  
  // program --help command
  if (!input.command && input.args.help && input.args.help !== true) {
    command = input.args.help;
    help = true;
  }
  
  return (help) ? command : false;
};

module.exports = help;
{'fraction_non_alphanumeric': 0.1641086186540732, 'fraction_numerical': 0.0025759364602339807, 'mean_word_length': 2.479462285287528, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '4278632', 'n_tokens_mistral': 3030, 'n_tokens_neox': 2988, 'n_words': 640}