<commit_before>import redent from 'redent';
import stripAnsi from 'strip-ansi';
import trimNewlines from 'trim-newlines';

import generateTable from '../generateTable';
import pad from '../helpers/pad';
import getCommandArgumentsAsString from '../../cli/commands/getCommandArgumentsAsString';
import getDefaultOptions from '../../cli/commands/getDefaultOptions';
import onProperty from '../../helpers/onProperty';
import isCommandGroup from '../../cli/commands/helpers/isCommandGroup';
import isCommand from '../../cli/commands/helpers/isCommand';
import getInfoObject from '../../validation/helpers/getInfoObject';
import objectToArray from '../../helpers/objectToArray';

import createStatefulAnchor from './helpers/createStatefulAnchor';

// Table with default options
const header = {
    name: {
        name: 'Name',
    },
    description: {
        name: 'Description',
        renderer: (input) => stripAnsi(input),
    },
    required: {
        name: 'Required',
        renderer: (input) => {
            if (input === true) {
                return 'Yes';
            }
            return 'No';
        },
    },
};

const settings = {
    groupTitleWrapper: (groupName, level) => `${pad(level + 3, '#')} ${
        groupName.charAt(0).toUpperCase() + groupName.slice(1)}`,
};

export default function commandsToMarkdown(
    name,
    config = {},
    commands,
    settingsLink,
    mode,
    hideCommands = [],
    cli = 'roc'
) {
    let rows = [];
    const allSettingGroups = config.settings ?
        Object.keys(config.settings).sort() :
        [];

    const printGroup = (group) => {
        const groupName = settingsLink ?
            `[${group}](${settingsLink}#${group})` :
            group;

        return `* ${groupName}`;
    };

    rows.push(`# Commands for \`${name}\``, '');

    if (commands) {
        rows.push('## General Information');
        rows.push('All commands can be called with some additional options illustrated in the table below.', '');

        rows.push(generateTable([{
            name: 'General options',
            level: 0,
            objects: getDefaultOptions('name'),
        }], header, settings));

        rows.push('## Commands');

        const { tableOfContent, content } =
            build(cli, commands, allSettingGroups, printGroup, hideCommands, createStatefulAnchor(mode));

        rows = rows.concat(tableOfContent, '', content, '');
    } else {
        rows.push('__No commands available.__', '');
    }<commit_msg>Only create documentation for commands if we have at least one command<commit_after>import redent from 'redent';
import stripAnsi from 'strip-ansi';
import trimNewlines from 'trim-newlines';

import generateTable from '../generateTable';
import pad from '../helpers/pad';
import getCommandArgumentsAsString from '../../cli/commands/getCommandArgumentsAsString';
import getDefaultOptions from '../../cli/commands/getDefaultOptions';
import onProperty from '../../helpers/onProperty';
import isCommandGroup from '../../cli/commands/helpers/isCommandGroup';
import isCommand from '../../cli/commands/helpers/isCommand';
import getInfoObject from '../../validation/helpers/getInfoObject';
import objectToArray from '../../helpers/objectToArray';

import createStatefulAnchor from './helpers/createStatefulAnchor';

// Table with default options
const header = {
    name: {
        name: 'Name',
    },
    description: {
        name: 'Description',
        renderer: (input) => stripAnsi(input),
    },
    required: {
        name: 'Required',
        renderer: (input) => {
            if (input === true) {
                return 'Yes';
            }
            return 'No';
        },
    },
};

const settings = {
    groupTitleWrapper: (groupName, level) => `${pad(level + 3, '#')} ${
        groupName.charAt(0).toUpperCase() + groupName.slice(1)}`,
};

export default function commandsToMarkdown(
    name,
    config = {},
    commands,
    settingsLink,
    mode,
    hideCommands = [],
    cli = 'roc'
) {
    let rows = [];
    const allSettingGroups = config.settings ?
        Object.keys(config.settings).sort() :
        [];

    const printGroup = (group) => {
        const groupName = settingsLink ?
            `[${group}](${settingsLink}#${group})` :
            group;

        return `* ${groupName}`;
    };

    rows.push(`# Commands for \`${name}\``, '');

    if (commands && Object.keys(commands).length > 0) {
        rows.push('## General Information');
        rows.push('All commands can be called with some additional options illustrated in the table below.', '');

        rows.push(generateTable([{
            name: 'General options',
            level: 0,
            objects: getDefaultOptions('name'),
        }], header, settings));

        rows.push('## Commands');

        const { tableOfContent, content } =
            build(cli, commands, allSettingGroups, printGroup, hideCommands, createStatefulAnchor(mode));

        rows = rows.concat(tableOfContent, '', content, '');
    } else {
        rows.push('__No commands available.__', '');
    }
{'fraction_non_alphanumeric': 0.15268225584594222, 'fraction_numerical': 0.0017685203379838867, 'mean_word_length': 2.6357142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '522433', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1394, 'n_words': 347}