Skip to content

Commit 29e6a78

Browse files
committed
Simplify aliases
1 parent fb9fccb commit 29e6a78

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

library/src/scala/annotation/newMain.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ final class newMain extends MainAnnotation[FromString, Any]:
6767

6868
extension (param: Parameter)
6969
private def aliasNames: Seq[String] =
70-
param.annotations.collect{ case a: Alias => a.aliases.map(getNameWithMarker) }.flatten
70+
param.annotations.collect{ case alias: Alias => getNameWithMarker(alias.name) }
7171

7272
private def getNameWithMarker(name: String): String =
7373
if name.length > 1 then s"--$name"
@@ -316,9 +316,8 @@ final class newMain extends MainAnnotation[FromString, Any]:
316316
throw IllegalArgumentException(s"The following argument name is invalid: ${param.name}")
317317
for annot <- param.annotations do
318318
annot match
319-
case alias: Alias =>
320-
for name <- alias.aliases if !isValidArgName(name) do
321-
throw IllegalArgumentException(s"The following alias is invalid: $name")
319+
case alias: Alias if !isValidArgName(alias.name) =>
320+
throw IllegalArgumentException(s"The following alias is invalid: ${alias.name}")
322321
case _ =>
323322

324323
checkValidNames()
@@ -329,6 +328,6 @@ end newMain
329328

330329
object newMain:
331330
@experimental
332-
final class Alias(val aliases: String*) extends MainAnnotation.ParameterAnnotation
331+
final class Alias(val name: String) extends MainAnnotation.ParameterAnnotation
333332

334333
end newMain

tests/run/main-annotation-help-override.check

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Error: missing argument for notH
3030
Usage: helpOverride7 [--notHelp | --help] <Int> [--notH | -h] <Int>
3131
Error: missing argument for --help
3232
Error: missing argument for notHelp
33-
Usage: helpOverride8 [--notHelp | --help | -h] <Int>
33+
Usage: helpOverride8 [--notHelp | -h | --help] <Int>
3434
##### -h
3535
Usage: helpOverride1 [--notHelp] <Int>
3636

@@ -63,4 +63,4 @@ Error: missing argument for notH
6363
Usage: helpOverride7 [--notHelp | --help] <Int> [--notH | -h] <Int>
6464
Error: missing argument for -h
6565
Error: missing argument for notHelp
66-
Usage: helpOverride8 [--notHelp | --help | -h] <Int>
66+
Usage: helpOverride8 [--notHelp | -h | --help] <Int>

tests/run/main-annotation-help-override.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object myProgram:
2626
@newMain def helpOverride7(@newMain.Alias("help") notHelp: Int, @newMain.Alias("h") notH: Int) = ???
2727

2828
/** A method that should not let --help and -h display help. */
29-
@newMain def helpOverride8(@newMain.Alias("help", "h") notHelp: Int) = ???
29+
@newMain def helpOverride8(@newMain.Alias("help") @newMain.Alias("h") notHelp: Int) = ???
3030

3131
end myProgram
3232

tests/run/main-annotation-param-annot-1.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ object myProgram:
4949
println(s"$num + $inc = ${num + inc}")
5050

5151
@newMain def multiple(
52-
@newMain.Alias("myNum", "n") num: Int,
53-
@newMain.Alias("i", "myInc") inc: Int
52+
@newMain.Alias("myNum") @newMain.Alias("n") num: Int,
53+
@newMain.Alias("i") @newMain.Alias("myInc") inc: Int
5454
): Unit =
5555
println(s"$num + $inc = ${num + inc}")
5656
end myProgram

0 commit comments

Comments
 (0)