@@ -13,6 +13,7 @@ import java.util
1313
1414import scala .build .info .{ArtifactId , BuildInfo , ExportDependencyFormat , ScopedBuildInfo }
1515import scala .build .internal .Constants
16+ import scala .build .internals .EnvVar
1617import scala .build .options .{BuildOptions , BuildRequirements , WithBuildRequirements }
1718import scala .build .preprocessing .directives .DirectiveHandler
1819import scala .build .preprocessing .directives .DirectivesPreprocessingUtils .*
@@ -606,6 +607,34 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
606607 b.mkString
607608 }
608609
610+ private def envVarContent (groups : Seq [EnvVar .EnvVarGroup ], onlyRestricted : Boolean ): String = {
611+ val b = new StringBuilder
612+ b.section(
613+ """ ---
614+ |title: Environment variables
615+ |sidebar_position: 7
616+ |---""" .stripMargin
617+ )
618+ b.section(
619+ """ Scala CLI uses environment variables to configure its behavior.
620+ |Below you can find a list of environment variables used and recognized by Scala CLI.
621+ |
622+ |However, it should by no means be treated as an exhaustive list.
623+ |Some tools and libraries Scala CLI integrates with may have their own, which may or may not be listed here.
624+ |""" .stripMargin
625+ )
626+ groups.foreach { group =>
627+ b.section(
628+ s " ## ${group.groupName}" ,
629+ group.all
630+ .filter(ev => ! ev.requiresPower || ! onlyRestricted)
631+ .map(ev => s " - ` ${ev.name}`: ${if ev.requiresPower then " ⚡ " else " " }${ev.description}" )
632+ .mkString(" \n " )
633+ )
634+ }
635+ b.mkString
636+ }
637+
609638 def run (options : InternalDocOptions , args : RemainingArgs ): Unit = {
610639
611640 val scalaCli = new ScalaCliCommands (
@@ -644,16 +673,21 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
644673 )
645674 val restrictedDocsDir = os.rel / " scala-command"
646675
676+ val allEnvVarsContent = envVarContent(EnvVar .allGroups, onlyRestricted = false )
677+ val restrictedEnvVarsContent = envVarContent(Seq (EnvVar .ScalaCli ), onlyRestricted = true )
678+
647679 if (options.check) {
648680 val content = Seq (
649681 (os.rel / " cli-options.md" ) -> allCliOptionsContent,
650682 (os.rel / " commands.md" ) -> allCommandsContent,
651683 (os.rel / " directives.md" ) -> allDirectivesContent,
652684 (os.rel / " build-info.md" ) -> buildInfoContent,
685+ (os.rel / " env-vars.md" ) -> allEnvVarsContent,
653686 (os.rel / restrictedDocsDir / " cli-options.md" ) -> restrictedCliOptionsContent,
654687 (os.rel / restrictedDocsDir / " commands.md" ) -> restrictedCommandsContent,
655688 (os.rel / restrictedDocsDir / " directives.md" ) -> restrictedDirectivesContent,
656- (os.rel / restrictedDocsDir / " runner-specification" ) -> scalaOptionsReference
689+ (os.rel / restrictedDocsDir / " runner-specification" ) -> scalaOptionsReference,
690+ (os.rel / restrictedDocsDir / " env-vars.md" ) -> restrictedEnvVarsContent
657691 )
658692 var anyDiff = false
659693 for ((dest, content0) <- content) {
@@ -678,6 +712,7 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
678712 maybeWrite(options.outputPath / " commands.md" , allCommandsContent)
679713 maybeWrite(options.outputPath / " directives.md" , allDirectivesContent)
680714 maybeWrite(options.outputPath / " build-info.md" , buildInfoContent)
715+ maybeWrite(options.outputPath / " env-vars.md" , allEnvVarsContent)
681716
682717 maybeWrite(
683718 options.outputPath / restrictedDocsDir / " cli-options.md" ,
@@ -692,6 +727,10 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
692727 options.outputPath / restrictedDocsDir / " runner-specification.md" ,
693728 scalaOptionsReference
694729 )
730+ maybeWrite(
731+ options.outputPath / restrictedDocsDir / " env-vars.md" ,
732+ restrictedEnvVarsContent
733+ )
695734 }
696735 }
697736}
0 commit comments