/* lib/terminal/commands/library/commands - Utility to list available commands and their respective documentation. */ import lists from "../../utilities/lists.js";
import wrapIt from "../../utilities/wrapIt.js";
import vars from "../../utilities/vars.js";
// CLI commands documentation generator
const commands = function terminal_commands_library_commands(name, callback) {
    let index = 0;
    const keys = name === "all" ? Object.keys(vars.terminal.commands) : [
        name
    ], length = keys.length, title = "Commands", output = [], named = function terminal_commands_library_commands_named() {
        // specifically mentioned option
        const comm = vars.terminal.commands[keys[index]], len = comm.example.length;
        let a = 0;
        output.push(vars.text.green + vars.text.bold + keys[index] + vars.text.none);
        wrapIt(output, comm.description);
        output.push("");
        do {
            wrapIt(output, `${vars.text.angry}*${vars.text.none} ${comm.example[a].defined}`);
            output.push(`   ${vars.text.cyan + comm.example[a].code + vars.text.none}`);
            output.push("");
            a = a + 1;
        }while (a < len)
        index = index + 1;
        if (index < length) {
            if (length > 1) {
                output.push("");
                output.push("---");
                output.push("");
            }
            terminal_commands_library_commands_named();
        } else {
            callback(title, output, null);
        }
    };
    if (name === null) {
        // all commands in a list
        const listConfig = {
            empty_line: false,
            heading: "Commands",
            obj: vars.terminal.commands,
            property: "description",
            total: true
        };
        lists(listConfig);
    } else {
        // command documentation by command name
        named();
    }
};
export default commands;
