Skip to content

Commit aeb1886

Browse files
committed
Include crucial config keys in the config sub-command short --help, while only showing others in --full-help
1 parent 06820c8 commit aeb1886

File tree

4 files changed

+55
-24
lines changed

4 files changed

+55
-24
lines changed

modules/cli/src/main/scala/scala/cli/commands/config/ConfigOptions.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scala.cli.commands.config
22

33
import caseapp.*
44

5+
import scala.build.internal.util.ConsoleUtils.ScalaCliConsole
56
import scala.cli.ScalaCli.{fullRunnerName, progName}
67
import scala.cli.commands.pgp.PgpScalaSigningOptions
78
import scala.cli.commands.shared.{
@@ -90,18 +91,24 @@ object ConfigOptions {
9091
private val websiteSuffix = s"misc/$cmdName"
9192
val helpMessage: String =
9293
s"""$helpHeader
94+
|
95+
|Available keys:
96+
| ${configKeysBulletPoints(includeHidden = false).mkString(s"${System.lineSeparator} ")}
9397
|
9498
|${HelpMessages.commandFullHelpReference(cmdName)}
9599
|${HelpMessages.commandDocWebsiteReference(websiteSuffix)}""".stripMargin
96-
private val configKeysBulletPoints: Seq[String] = {
97-
val keys: Seq[Key[_]] = Keys.map.values.toSeq
98-
val maxFullNameLength = keys.map(_.fullName.length).max
100+
private def configKeysBulletPoints(includeHidden: Boolean): Seq[String] = {
101+
val allKeys: Seq[Key[_]] = Keys.map.values.toSeq
102+
val keys: Seq[Key[_]] = if includeHidden then allKeys else allKeys.filterNot(_.hidden)
103+
val maxFullNameLength = keys.map(_.fullName.length).max
99104
keys.sortBy(_.fullName)
100105
.map { key =>
101106
val currentKeyFullNameLength = maxFullNameLength - key.fullName.length
102107
val extraSpaces =
103108
if currentKeyFullNameLength > 0 then " " * currentKeyFullNameLength else ""
104-
s"- ${Console.YELLOW}${key.fullName}${Console.RESET}$extraSpaces ${key.description}"
109+
val hiddenString =
110+
if key.hidden then s"${ScalaCliConsole.GRAY}(hidden)${Console.RESET} " else ""
111+
s"- ${Console.YELLOW}${key.fullName}${Console.RESET}$extraSpaces $hiddenString${key.description}"
105112
}
106113
}
107114
val detailedHelpMessage: String =
@@ -113,7 +120,7 @@ object ConfigOptions {
113120
| ${Console.BOLD}$progName $cmdName interactive true${Console.RESET}
114121
|
115122
|Available keys:
116-
| ${configKeysBulletPoints.mkString(s"${System.lineSeparator} ")}
123+
| ${configKeysBulletPoints(includeHidden = true).mkString(s"${System.lineSeparator} ")}
117124
|
118125
|${HelpMessages.commandDocWebsiteReference(websiteSuffix)}""".stripMargin
119126
}

modules/config/src/main/scala/scala/cli/config/Key.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ abstract class Key[T] {
4141
/** A short description of a particular key's purpose and syntax for its values. */
4242
def description: String
4343

44+
/** A flag indicating whether the key should by default be hidden in help outputs or not. */
45+
def hidden: Boolean = false
46+
4447
/** Whether this key corresponds to a password (see [[Key.PasswordEntry]]) */
4548
def isPasswordOption: Boolean = false
4649
}
@@ -80,7 +83,8 @@ object Key {
8083
final class StringEntry(
8184
val prefix: Seq[String],
8285
val name: String,
83-
val description: String = ""
86+
val description: String = "",
87+
override val hidden: Boolean = false
8488
) extends Key[String] {
8589
def parse(json: Array[Byte]): Either[EntryError, String] =
8690
try Right(readFromArray(json)(stringCodec))
@@ -102,7 +106,8 @@ object Key {
102106
final class BooleanEntry(
103107
val prefix: Seq[String],
104108
val name: String,
105-
val description: String = ""
109+
val description: String = "",
110+
override val hidden: Boolean = false
106111
) extends Key[Boolean] {
107112
def parse(json: Array[Byte]): Either[EntryError, Boolean] =
108113
try Right(readFromArray(json)(booleanCodec))
@@ -124,7 +129,8 @@ object Key {
124129
final class PasswordEntry(
125130
val prefix: Seq[String],
126131
val name: String,
127-
val description: String = ""
132+
val description: String = "",
133+
override val hidden: Boolean = false
128134
) extends Key[PasswordOption] {
129135
def parse(json: Array[Byte]): Either[EntryError, PasswordOption] =
130136
try {
@@ -157,7 +163,8 @@ object Key {
157163
final class StringListEntry(
158164
val prefix: Seq[String],
159165
val name: String,
160-
val description: String = ""
166+
val description: String = "",
167+
override val hidden: Boolean = false
161168
) extends Key[List[String]] {
162169
def parse(json: Array[Byte]): Either[EntryError, List[String]] =
163170
try Right(readFromArray(json)(stringListCodec))

modules/config/src/main/scala/scala/cli/config/Keys.scala

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,46 @@ object Keys {
1010
val userName = new Key.StringEntry(
1111
prefix = Seq("publish", "user"),
1212
name = "name",
13-
description = "The 'name' user detail, used for publishing."
13+
description = "The 'name' user detail, used for publishing.",
14+
hidden = true
1415
)
1516
val userEmail = new Key.StringEntry(
1617
prefix = Seq("publish", "user"),
1718
name = "email",
18-
description = "The 'email' user detail, used for publishing."
19+
description = "The 'email' user detail, used for publishing.",
20+
hidden = true
1921
)
2022
val userUrl = new Key.StringEntry(
2123
prefix = Seq("publish", "user"),
2224
name = "url",
23-
description = "The 'url' user detail, used for publishing."
25+
description = "The 'url' user detail, used for publishing.",
26+
hidden = true
2427
)
2528

2629
val ghToken = new Key.PasswordEntry(
2730
prefix = Seq("github"),
2831
name = "token",
29-
description = "GitHub token."
32+
description = "GitHub token.",
33+
hidden = true
3034
)
3135

3236
val pgpSecretKey = new Key.PasswordEntry(
3337
prefix = Seq("pgp"),
3438
name = "secret-key",
35-
description = "The PGP secret key, used for signing."
39+
description = "The PGP secret key, used for signing.",
40+
hidden = true
3641
)
3742
val pgpSecretKeyPassword = new Key.PasswordEntry(
3843
prefix = Seq("pgp"),
3944
name = "secret-key-password",
40-
description = "The PGP secret key password, used for signing."
45+
description = "The PGP secret key password, used for signing.",
46+
hidden = true
4147
)
4248
val pgpPublicKey = new Key.PasswordEntry(
4349
prefix = Seq("pgp"),
4450
name = "public-key",
45-
description = "The PGP public key, used for signing."
51+
description = "The PGP public key, used for signing.",
52+
hidden = true
4653
)
4754

4855
val actions = new Key.BooleanEntry(
@@ -78,30 +85,35 @@ object Keys {
7885
val proxyAddress = new Key.StringEntry(
7986
prefix = Seq("httpProxy"),
8087
name = "address",
81-
description = "HTTP proxy address."
88+
description = "HTTP proxy address.",
89+
hidden = true
8290
)
8391
val proxyUser = new Key.PasswordEntry(
8492
prefix = Seq("httpProxy"),
8593
name = "user",
86-
description = "HTTP proxy user (used for authentication)."
94+
description = "HTTP proxy user (used for authentication).",
95+
hidden = true
8796
)
8897
val proxyPassword = new Key.PasswordEntry(
8998
prefix = Seq("httpProxy"),
9099
name = "password",
91-
description = "HTTP proxy password (used for authentication)."
100+
description = "HTTP proxy password (used for authentication).",
101+
hidden = true
92102
)
93103

94104
val repositoryMirrors = new Key.StringListEntry(
95105
prefix = Seq("repositories"),
96106
name = "mirrors",
97107
description =
98-
s"Repository mirrors, syntax: repositories.mirrors maven:*=https://repository.company.com/maven"
108+
s"Repository mirrors, syntax: repositories.mirrors maven:*=https://repository.company.com/maven",
109+
hidden = true
99110
)
100111
val defaultRepositories = new Key.StringListEntry(
101112
prefix = Seq("repositories"),
102113
name = "default",
103114
description =
104-
"Default repository, syntax: https://first-repo.company.com https://second-repo.company.com"
115+
"Default repository, syntax: https://first-repo.company.com https://second-repo.company.com",
116+
hidden = true
105117
)
106118

107119
// Kept for binary compatibility
@@ -111,7 +123,8 @@ object Keys {
111123
val globalInteractiveWasSuggested = new Key.BooleanEntry(
112124
prefix = Seq.empty,
113125
name = "interactive-was-suggested",
114-
description = "Setting indicating if the global interactive mode was already suggested."
126+
description = "Setting indicating if the global interactive mode was already suggested.",
127+
hidden = true
115128
)
116129

117130
def all: Seq[Key[_]] = Seq[Key[_]](
@@ -196,6 +209,7 @@ object Keys {
196209
val repositoryCredentials: Key[List[RepositoryCredentials]] =
197210
new Key[List[RepositoryCredentials]] {
198211
override val description: String = "Repository credentials, syntax: value:user value:password"
212+
override val hidden: Boolean = true
199213

200214
private def asJson(credentials: RepositoryCredentials): RepositoryCredentialsAsJson =
201215
RepositoryCredentialsAsJson(
@@ -320,6 +334,7 @@ object Keys {
320334
val publishCredentials: Key[List[PublishCredentials]] = new Key[List[PublishCredentials]] {
321335
override val description: String =
322336
"Publishing credentials, syntax: s1.oss.sonatype.org value:user value:password"
337+
override val hidden: Boolean = true
323338

324339
private def asJson(credentials: PublishCredentials): PublishCredentialsAsJson =
325340
PublishCredentialsAsJson(

modules/generate-reference-doc/src/main/scala/scala/cli/doc/ReferenceDocUtils.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ object ReferenceDocUtils {
4343
consoleToFenceRec(remainingLines.tail, newFenceOpen, newAcc)
4444
consoleToFenceRec(s.linesIterator.toSeq)
4545
}
46+
def filterOutHiddenStrings: String =
47+
s.replace(s"${ScalaCliConsole.GRAY}(hidden)${Console.RESET} ", "")
4648
}
4749
extension (helpMessage: HelpMessage) {
48-
def referenceDocMessage: String = helpMessage.message.consoleToFence.noConsoleKeys
50+
def referenceDocMessage: String = helpMessage.message.filterOutHiddenStrings.consoleToFence
4951
def referenceDocDetailedMessage: String = {
5052
val msg =
5153
if helpMessage.detailedMessage.nonEmpty then helpMessage.detailedMessage
5254
else helpMessage.message
53-
msg.consoleToFence
55+
msg.filterOutHiddenStrings.consoleToFence
5456
}
5557
}
5658

0 commit comments

Comments
 (0)