Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1874 from Gedochao/adjust-reference-docs
Ensure no console-syntax in reference docs and no `md` fenced blocks in `--help`
- Loading branch information
Showing
16 changed files
with
525 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
modules/build/src/main/scala/scala/build/internal/util/ConsoleUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package scala.build.internal.util | ||
|
||
object ConsoleUtils { | ||
import Console.* | ||
|
||
object ScalaCliConsole { | ||
val GRAY: String = "\u001b[90m" | ||
} | ||
|
||
val ansiFormattingKeys: Set[String] = Set(RESET, BOLD, UNDERLINED, REVERSED, INVISIBLE) | ||
val ansiColors: Set[String] = | ||
Set(BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, ScalaCliConsole.GRAY) | ||
val ansiBoldColors: Set[String] = | ||
Set(BLACK_B, RED_B, GREEN_B, YELLOW_B, BLUE_B, MAGENTA_B, CYAN_B, WHITE_B) | ||
val allAnsiColors: Set[String] = ansiColors ++ ansiBoldColors | ||
val allConsoleKeys: Set[String] = allAnsiColors ++ ansiFormattingKeys | ||
|
||
extension (s: String) { | ||
def noConsoleKeys: String = | ||
allConsoleKeys.fold(s)((acc, consoleKey) => acc.replace(consoleKey, "")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
modules/generate-reference-doc/src/main/scala/scala/cli/doc/ReferenceDocUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package scala.cli.doc | ||
|
||
import caseapp.HelpMessage | ||
|
||
import java.util.stream.IntStream | ||
|
||
import scala.build.internal.util.ConsoleUtils.* | ||
|
||
object ReferenceDocUtils { | ||
extension (s: String) { | ||
def consoleToFence: String = | ||
s | ||
.linesIterator | ||
.fold("") { (acc, line) => | ||
val maybeOpenFence = | ||
if line.contains(Console.BOLD) then | ||
"""```sh | ||
|""".stripMargin | ||
else if line.contains(ScalaCliConsole.GRAY) then | ||
"""```scala | ||
|""".stripMargin | ||
else "" | ||
val maybeCloseFence = | ||
if line.contains(Console.RESET) then | ||
""" | ||
|```""".stripMargin | ||
else "" | ||
val newLine = s"$maybeOpenFence${line.noConsoleKeys}$maybeCloseFence" | ||
if acc.isEmpty then newLine | ||
else s"""$acc | ||
|$newLine""".stripMargin | ||
} | ||
} | ||
extension (helpMessage: HelpMessage) { | ||
def referenceDocMessage: String = helpMessage.message.consoleToFence.noConsoleKeys | ||
def referenceDocDetailedMessage: String = { | ||
val msg = | ||
if helpMessage.detailedMessage.nonEmpty then helpMessage.detailedMessage | ||
else helpMessage.message | ||
msg.consoleToFence | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.