Skip to content

Commit fa9a7f3

Browse files
Split Arg into ShortName and Name
- Allow for multiple parameter annotations - Rework the code of main to reflect changes and simplify treatment - Change output of help and usage to accomodate for multiple names
1 parent 17c65dd commit fa9a7f3

12 files changed

+307
-227
lines changed

library/src/scala/main.scala

Lines changed: 135 additions & 83 deletions
Large diffs are not rendered by default.

project/MiMaFilters.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ object MiMaFilters {
99
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.main.this"),
1010
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.main.command"),
1111
ProblemFilters.exclude[MissingClassProblem]("scala.main$"),
12-
ProblemFilters.exclude[MissingClassProblem]("scala.main$Arg"),
13-
ProblemFilters.exclude[MissingClassProblem]("scala.main$Arg$"),
12+
ProblemFilters.exclude[MissingClassProblem]("scala.main$Name"),
13+
ProblemFilters.exclude[MissingClassProblem]("scala.main$Name$"),
14+
ProblemFilters.exclude[MissingClassProblem]("scala.main$ShortName"),
15+
ProblemFilters.exclude[MissingClassProblem]("scala.main$ShortName$"),
1416
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation"),
1517
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$"),
1618
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$Command"),

tests/run/main-annotation-help.check

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,157 +2,157 @@ Usage: doc1 [--num] <Int> [--inc] <Int>
22

33
Adds two numbers.
44
Arguments:
5-
num - Int
6-
inc - Int
5+
--num - Int
6+
--inc - Int
77
Usage: doc1 [--num] <Int> [--inc] <Int>
88

99
Adds two numbers.
1010
Arguments:
11-
num - Int
12-
inc - Int
11+
--num - Int
12+
--inc - Int
1313
Usage: doc1 [--num] <Int> [--inc] <Int>
1414

1515
Adds two numbers.
1616
Arguments:
17-
num - Int
18-
inc - Int
17+
--num - Int
18+
--inc - Int
1919
Usage: doc1 [--num] <Int> [--inc] <Int>
2020

2121
Adds two numbers.
2222
Arguments:
23-
num - Int
24-
inc - Int
23+
--num - Int
24+
--inc - Int
2525
Usage: doc2 [--num] <Int> [--inc] <Int>
2626

2727
Adds two numbers.
2828
Arguments:
29-
num - Int
30-
inc - Int
29+
--num - Int
30+
--inc - Int
3131
Usage: doc3 [--num] <Int> [--inc] <Int>
3232

3333
Adds two numbers.
3434
Arguments:
35-
num - Int
36-
inc - Int
35+
--num - Int
36+
--inc - Int
3737
Usage: doc4 [--num] <Int> [[--inc] <Int>]
3838

3939
Adds two numbers.
4040
Arguments:
41-
num - Int
41+
--num - Int
4242
the first number
43-
inc - Int (optional)
43+
--inc - Int (optional)
4444
the second number
4545
Usage: doc5 [--num] <Int> [--inc] <Int>
4646

4747
Adds two numbers.
4848
Arguments:
49-
num - Int
49+
--num - Int
5050
the first number
51-
inc - Int
51+
--inc - Int
5252
Usage: doc6 [--num] <Int> [--inc] <Int>
5353

5454
Adds two numbers.
5555
Arguments:
56-
num - Int
57-
inc - Int
56+
--num - Int
57+
--inc - Int
5858
Usage: doc7 [--num] <Int> [--inc] <Int>
5959

6060
Adds two numbers.
6161
Arguments:
62-
num - Int
62+
--num - Int
6363
the first number
64-
inc - Int
64+
--inc - Int
6565
the second number
6666
Usage: doc8 [--num] <Int> [--inc] <Int>
6767

6868
Adds two numbers.
6969
Arguments:
70-
num - Int
70+
--num - Int
7171
the first number
72-
inc - Int
72+
--inc - Int
7373
the second number
7474
Usage: doc9 [--num] <Int> [--inc] <Int>
7575

7676
Adds two numbers. Same as doc1.
7777
Arguments:
78-
num - Int
78+
--num - Int
7979
the first number
80-
inc - Int
80+
--inc - Int
8181
the second number
8282
Usage: doc10 [--num] <Int> [--inc] <Int>
8383

8484
Adds two numbers.
8585
This should be on another line.
8686
And this also.
8787
Arguments:
88-
num - Int
88+
--num - Int
8989
I might have to write this on two lines
90-
inc - Int
90+
--inc - Int
9191
I might even have to write this one on three lines
9292
Usage: doc11 [--num] <Int> [--inc] <Int>
9393

9494
Adds two numbers.
9595
Arguments:
96-
num - Int
96+
--num - Int
9797
the first number
9898
Oh, a new line!
99-
inc - Int
99+
--inc - Int
100100
the second number
101101
And another one!
102102
Usage: doc12 [--num] <Int> [--inc] <Int>
103103

104104
Adds two numbers. It seems that I have a very long line of documentation and therefore might need to be cut at some
105105
point to fit a small terminal screen.
106106
Arguments:
107-
num - Int
108-
inc - Int
107+
--num - Int
108+
--inc - Int
109109
Usage: doc13 [--num] <Int> [--inc] <Int>
110110

111111
Addstwonumbers.ItseemsthatIhaveaverylonglineofdocumentationandthereforemightneedtobecutatsomepointtofitasmallterminalscreen.
112112
Arguments:
113-
num - Int
114-
inc - Int
113+
--num - Int
114+
--inc - Int
115115
Usage: doc14 [--arg1] <String> [--arg2] <Int> [--arg3] <String> [--arg4] <Int> [--arg5] <String> [--arg6] <Int>
116116
[--arg7] <String> [--arg8] <Int> [[--arg9] <String>] [[--arg10] <Int>] [[--arg11] <String>]
117117
[[--arg12] <Int>] [[--arg13] <String>] [[--arg14] <Int>] [[--arg15] <String>] [<Int> [<Int> [...]]]
118118

119119
Loudly judges the number of argument you gave to this poor function.
120120
Arguments:
121-
arg1 - String
122-
arg2 - Int
123-
arg3 - String
124-
arg4 - Int
125-
arg5 - String
126-
arg6 - Int
127-
arg7 - String
128-
arg8 - Int
129-
arg9 - String (optional)
130-
arg10 - Int (optional)
131-
arg11 - String (optional)
132-
arg12 - Int (optional)
133-
arg13 - String (optional)
134-
arg14 - Int (optional)
135-
arg15 - String (optional)
136-
arg16 - Int (vararg)
121+
--arg1 - String
122+
--arg2 - Int
123+
--arg3 - String
124+
--arg4 - Int
125+
--arg5 - String
126+
--arg6 - Int
127+
--arg7 - String
128+
--arg8 - Int
129+
--arg9 - String (optional)
130+
--arg10 - Int (optional)
131+
--arg11 - String (optional)
132+
--arg12 - Int (optional)
133+
--arg13 - String (optional)
134+
--arg14 - Int (optional)
135+
--arg15 - String (optional)
136+
--arg16 - Int (vararg)
137137
Usage: doc15 [--myNum] <MyNumber> [--myInc] <MyNumber>
138138

139139
Adds two instances of MyNumber.
140140
Arguments:
141-
myNum - MyNumber
141+
--myNum - MyNumber
142142
my first number to add
143-
myInc - MyNumber
143+
--myInc - MyNumber
144144
my second number to add
145145
Usage: doc16 [--first] <MyGeneric[Int]> [--second] <MyGeneric[Int]>
146146

147147
Compares two instances of MyGeneric.
148148
Arguments:
149-
first - MyGeneric[Int]
149+
--first - MyGeneric[Int]
150150
my first element
151-
second - MyGeneric[Int]
151+
--second - MyGeneric[Int]
152152
my second element
153153
Usage: doc17 [--a] <Int> [--b] <Int> [--c] <String>
154154

155155
Arguments:
156-
a - Int
157-
b - Int
158-
c - String
156+
--a - Int
157+
--b - Int
158+
--c - String

tests/run/main-annotation-max-line-length.check

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ Usage: doc1 [--a] <Int> [--b] <Int> [--c] <String>
22

33
Help is printed normally.
44
Arguments:
5-
a - Int
5+
--a - Int
66
the first argument
7-
b - Int
7+
--b - Int
88
the second argument
9-
c - String
9+
--c - String
1010
the third argument. This one is a String
1111
Usage: doc2 [--a] <Int> [--b] <Int>
1212
[--c] <String>
1313

1414
Help is printed in a slightly narrow
1515
column.
1616
Arguments:
17-
a - Int
17+
--a - Int
1818
the first argument
19-
b - Int
19+
--b - Int
2020
the second argument
21-
c - String
21+
--c - String
2222
the third argument. This one is a
2323
String
2424
Usage: doc3 [--a] <Int>
@@ -28,13 +28,13 @@ Usage: doc3 [--a] <Int>
2828
Help is printed in a
2929
very narrow column!
3030
Arguments:
31-
a - Int
31+
--a - Int
3232
the first
3333
argument
34-
b - Int
34+
--b - Int
3535
the second
3636
argument
37-
c - String
37+
--c - String
3838
the third
3939
argument. This
4040
one is a String
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2 + 3 = 5
2+
2 + 3 = 5
3+
2 + 3 = 5
4+
2 + 3 = 5
5+
2 + 3 = 5
6+
2 + 3 = 5
7+
2 + 3 = 5
8+
2 + 3 = 5
9+
2 + 3 = 5
10+
2 + 3 = 5
11+
2 + 3 = 5
12+
2 + 3 = 5
13+
2 + 3 = 5
14+
2 + 3 = 5
15+
2 + 3 = 5
16+
2 + 3 = 5
17+
2 + 3 = 5
18+
2 + 3 = 5
19+
2 + 3 = 5
20+
2 + 3 = 5
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,33 @@
11
object myProgram:
2-
@main def noParamAnnotArgs(
3-
@main.Arg() num: Int,
4-
@main.Arg() inc: Int
5-
): Unit =
6-
println(s"$num + $inc = ${num + inc}")
7-
82
@main def altName1(
9-
@main.Arg(name = "myNum") num: Int,
3+
@main.Name("myNum") num: Int,
104
inc: Int
115
): Unit =
126
println(s"$num + $inc = ${num + inc}")
137

148
@main def altName2(
15-
@main.Arg(name = "myNum") num: Int,
16-
@main.Arg(name = "myInc") inc: Int
9+
@main.Name("myNum") num: Int,
10+
@main.Name("myInc") inc: Int
1711
): Unit =
1812
println(s"$num + $inc = ${num + inc}")
1913

2014
@main def shortName1(
21-
@main.Arg(shortName = 'n') num: Int,
15+
@main.ShortName('n') num: Int,
2216
inc: Int
2317
): Unit =
2418
println(s"$num + $inc = ${num + inc}")
2519

2620
@main def shortName2(
27-
@main.Arg(shortName = 'n') num: Int,
28-
@main.Arg(shortName = 'i') inc: Int
21+
@main.ShortName('n') num: Int,
22+
@main.ShortName('i') inc: Int
2923
): Unit =
3024
println(s"$num + $inc = ${num + inc}")
3125

3226
@main def mix(
33-
@main.Arg(name = "myNum", shortName = 'n') num: Int,
34-
@main.Arg(shortName = 'i', name = "myInc") inc: Int
27+
@main.Name("myNum") @main.ShortName('n') num: Int,
28+
@main.ShortName('i') @main.Name("myInc") inc: Int
3529
): Unit =
3630
println(s"$num + $inc = ${num + inc}")
37-
38-
@main def multipleSameShortName(
39-
@main.Arg(shortName = 'n') num: Int,
40-
@main.Arg(shortName = 'n') inc: Int
41-
): Unit = ()
4231
end myProgram
4332

4433

@@ -49,8 +38,6 @@ object Test:
4938
method.invoke(null, args)
5039

5140
def main(args: Array[String]): Unit =
52-
callMain("noParamAnnotArgs", Array("--num", "2", "--inc", "3"))
53-
5441
callMain("altName1", Array("--num", "2", "--inc", "3"))
5542
callMain("altName1", Array("--myNum", "2", "--inc", "3"))
5643

@@ -75,6 +62,4 @@ object Test:
7562
callMain("mix", Array("-n", "2", "--myInc", "3"))
7663
callMain("mix", Array("--myNum", "2", "-i", "3"))
7764
callMain("mix", Array("-n", "2", "-i", "3"))
78-
79-
callMain("multipleSameShortName", Array("2", "3"))
8065
end Test
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
OK
2+
OK
3+
OK
4+
OK
5+
OK
6+
OK
7+
OK
8+
OK
9+
OK

0 commit comments

Comments
 (0)