diff --git a/internal/documentation/scripts/generateCliDoc.js b/internal/documentation/scripts/generateCliDoc.js
index e833dff57b7..84b48f9384d 100644
--- a/internal/documentation/scripts/generateCliDoc.js
+++ b/internal/documentation/scripts/generateCliDoc.js
@@ -1,219 +1,37 @@
-import {execSync as exec} from "node:child_process";
import {readFileSync, writeFileSync} from "node:fs";
import {fileURLToPath} from "node:url";
import Handlebars from "handlebars";
+import {buildCliModel} from "./lib/cliModel.js";
const source = readFileSync(fileURLToPath(new URL("./resources/CLI.template.md", import.meta.url)), "utf8");
const template = Handlebars.compile(source);
-
-let first = true;
-const obj = {
- common: "",
- usage: "",
- desc: "",
- positionals: [],
- commands: [],
- commonOptions: [],
- addOptions: [],
- examples: [],
-};
-
-function execute(command) {
- parseOutput(exec(command).toString());
-}
-
-function parseOutput(stdout) {
- const sections = stdout.split("\n\n");
- if (first) {
- for (const section of sections) {
- if (section.includes("Usage:")) {
- obj.common = section;
- }
- if (section.includes("Options:")) {
- obj.commonOptions = section.split("\n");
- }
- if (section.includes("Examples:")) {
- obj.examples = section.split("\n");
- }
- if (section.includes("Commands:")) {
- obj.commands = section.split("\n");
- }
- }
- first = false;
- } else {
- if (sections[0].includes("local")) {
- obj.usage = sections[1];
- obj.desc = sections[2];
- } else {
- obj.usage = sections[0];
- obj.desc = sections[1];
- }
-
- obj.commands = [];
- obj.examples = [];
- obj.positionals = [];
- obj.addOptions = [];
- for (const section of sections) {
- if (section.includes("Positionals:")) {
- obj.positionals = section.split("\n");
- }
- if (section.includes("Options:")) {
- obj.addOptions = section.split("\n").filter(function(el) {
- const array = obj.commonOptions;
- array.forEach(function(item, index, array) {
- array[index] = item.replace(/\s+/g, "");
- });
- return !array.includes(el.replace(/\s+/g, ""));
- });
- }
- if (section.includes("Examples:")) {
- obj.examples = section.split("\n");
- }
- if (section.includes("Commands:")) {
- obj.commands = section.split("\n");
- }
- }
- }
+const model = await buildCliModel();
+
+let content = template({
+ // The template renders the usage inside backticks; strip the "Usage:" label
+ common: model.common.split("Usage:").join(""),
+ commonOptions: model.commonOptions,
+ commonExamples: model.commonExamples,
+ commands: model.commands,
+});
+
+content = content
+ .split("<").join("<")
+ .split(">").join(">")
+ // Escape