@@ -13,6 +13,7 @@ import java.util
13
13
14
14
import scala .build .info .{ArtifactId , BuildInfo , ExportDependencyFormat , ScopedBuildInfo }
15
15
import scala .build .internal .Constants
16
+ import scala .build .internals .EnvVar
16
17
import scala .build .options .{BuildOptions , BuildRequirements , WithBuildRequirements }
17
18
import scala .build .preprocessing .directives .DirectiveHandler
18
19
import scala .build .preprocessing .directives .DirectivesPreprocessingUtils .*
@@ -606,6 +607,34 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
606
607
b.mkString
607
608
}
608
609
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
+
609
638
def run (options : InternalDocOptions , args : RemainingArgs ): Unit = {
610
639
611
640
val scalaCli = new ScalaCliCommands (
@@ -644,16 +673,21 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
644
673
)
645
674
val restrictedDocsDir = os.rel / " scala-command"
646
675
676
+ val allEnvVarsContent = envVarContent(EnvVar .allGroups, onlyRestricted = false )
677
+ val restrictedEnvVarsContent = envVarContent(Seq (EnvVar .ScalaCli ), onlyRestricted = true )
678
+
647
679
if (options.check) {
648
680
val content = Seq (
649
681
(os.rel / " cli-options.md" ) -> allCliOptionsContent,
650
682
(os.rel / " commands.md" ) -> allCommandsContent,
651
683
(os.rel / " directives.md" ) -> allDirectivesContent,
652
684
(os.rel / " build-info.md" ) -> buildInfoContent,
685
+ (os.rel / " env-vars.md" ) -> allEnvVarsContent,
653
686
(os.rel / restrictedDocsDir / " cli-options.md" ) -> restrictedCliOptionsContent,
654
687
(os.rel / restrictedDocsDir / " commands.md" ) -> restrictedCommandsContent,
655
688
(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
657
691
)
658
692
var anyDiff = false
659
693
for ((dest, content0) <- content) {
@@ -678,6 +712,7 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
678
712
maybeWrite(options.outputPath / " commands.md" , allCommandsContent)
679
713
maybeWrite(options.outputPath / " directives.md" , allDirectivesContent)
680
714
maybeWrite(options.outputPath / " build-info.md" , buildInfoContent)
715
+ maybeWrite(options.outputPath / " env-vars.md" , allEnvVarsContent)
681
716
682
717
maybeWrite(
683
718
options.outputPath / restrictedDocsDir / " cli-options.md" ,
@@ -692,6 +727,10 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
692
727
options.outputPath / restrictedDocsDir / " runner-specification.md" ,
693
728
scalaOptionsReference
694
729
)
730
+ maybeWrite(
731
+ options.outputPath / restrictedDocsDir / " env-vars.md" ,
732
+ restrictedEnvVarsContent
733
+ )
695
734
}
696
735
}
697
736
}
0 commit comments