From a90a2f50bc59a8099e289f90f814b486f218a8f0 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 8 Feb 2018 20:43:10 +0100 Subject: [PATCH] Avoid duplicated SWNAMES in to auto-generated CLI output --- ddoc_preprocessor.d | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ddoc_preprocessor.d b/ddoc_preprocessor.d index 909b18463d..f28fd56744 100755 --- a/ddoc_preprocessor.d +++ b/ddoc_preprocessor.d @@ -286,6 +286,9 @@ auto genSwitches(string fileText) { enum ddocKey = "$(CLI_SWITCHES"; auto content = ddocKey ~ "\n"; + + bool[string] seen; + foreach (option; Usage.options) { string flag = option.flag; @@ -299,10 +302,21 @@ auto genSwitches(string fileText) highlightSpecialWords(flag, helpText); auto flagEndPos = flag.representation.countUntil("=", "$(", "<"); string switchName; + + string swNameMacro = "SWNAME"; + // flags links should be unique + auto swKey = flag[0 .. flagEndPos < 0 ? $ : flagEndPos]; + if (auto v = swKey in seen) + { + swNameMacro = "B"; + swKey.writeln; + } + seen[swKey] = 1; + if (flagEndPos < 0) - switchName = "$(SWNAME -%s)".format(flag); + switchName = "$(%s -%s)".format(swNameMacro, flag); else - switchName = "$(SWNAME -%s)%s".format(flag[0..flagEndPos], flag[flagEndPos..$].escapeDdoc); + switchName = "$(%s -%s)%s".format(swNameMacro, flag[0..flagEndPos], flag[flagEndPos..$].escapeDdoc); auto currentFlag = "$(SWITCH %s,\n %s