<commit_before>const { spawnSync } = require('child_process');
const { platform } = require('os');

function getHelp(command, sub) {
  const proc = runCommand(command, ['--help']);

  function render(data) {
    parsed = parseOutput(command, data.replace(/`/g, ''));
    console.log(markdownForCommand(parsed, sub));

    parsed.subcommands.forEach(item => {
      getHelp(`${item.parent} ${item.command}`, item.parent !== 'hab');
    });
  }

  render(proc.stdout.toString());
}

function runCommand(command, args) {
  return spawnSync(command, args, { shell: true });
}

function parseOutput(command, output) {
  const lines = output.split('\n');
  const sections = output.split('\n\n');

  let result = {
    name: lines[0].trim(),
    description: lines[1].trim()
  };

  sections.forEach(s => {
    const c = s.indexOf(':');
    const heading = s.slice(0, c).trim();
    const body = s.slice(c + 1);
    result[heading.trim()] = body
      .trim()
      .replace(/(\n[ ]{9,})[\W]/gm, ' ')<commit_msg>split sections by custom token when generating cli docs<commit_after>const { spawnSync } = require('child_process');
const { platform } = require('os');

function getHelp(command, sub) {
  const proc = runCommand(command, ['--help']);

  function render(data) {
    parsed = parseOutput(command, data.replace(/`/g, ''));
    console.log(markdownForCommand(parsed, sub));

    parsed.subcommands.forEach(item => {
      getHelp(`${item.parent} ${item.command}`, item.parent !== 'hab');
    });
  }

  render(proc.stdout.toString());
}

function runCommand(command, args) {
  return spawnSync(command, args, { shell: true });
}

function parseOutput(command, output) {
  const sectionToken = '\^/--IMATOKEN--\^/';

  const lines = output.split('\n');
  const sections = output.replace(/\n\n(.+):\n/g, sectionToken + '$1:').split(sectionToken);

  let result = {
    name: lines[0].trim(),
    description: lines[1].trim()
  };

  sections.forEach(s => {
    const c = s.indexOf(':');
    const heading = s.slice(0, c).trim();
    const body = s.slice(c + 1);
    result[heading.trim()] = body
      .trim()
      .replace(/(\n[ ]{9,})[\W]/gm, ' ')
{'fraction_non_alphanumeric': 0.20232558139534884, 'fraction_numerical': 0.0051162790697674414, 'mean_word_length': 3.576595744680851, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '951074', 'n_tokens_mistral': 716, 'n_tokens_neox': 706, 'n_words': 145}