@@ -7,8 +7,8 @@ import collection.mutable
7
7
* The protocol of calls from compiler-main is as follows:
8
8
*
9
9
* - create a `command` with the command line arguments,
10
- * - for each parameter of user-main, a call to `command.argGetter `,
11
- * or `command.argsGetter ` if is a final varargs parameter,
10
+ * - for each parameter of user-main, a call to `command.nextArgGetter `,
11
+ * or `command.finalArgsGetter ` if is a final varargs parameter,
12
12
* - a call to `command.run` with the closure of user-main applied to all arguments.
13
13
*
14
14
* The wrapper class has this outline:
@@ -46,10 +46,10 @@ trait MainAnnotation extends StaticAnnotation:
46
46
abstract class Command :
47
47
48
48
/** The getter for the next argument of type `T` */
49
- def argGetter [T ](argName : String , fromString : ArgumentParser [T ], defaultValue : Option [T ] = None ): () => T
49
+ def nextArgGetter [T ](argName : String , fromString : ArgumentParser [T ], defaultValue : Option [T ] = None ): () => T
50
50
51
51
/** The getter for a final varargs argument of type `T*` */
52
- def argsGetter [T ](argName : String , fromString : ArgumentParser [T ]): () => Seq [T ]
52
+ def finalArgsGetter [T ](argName : String , fromString : ArgumentParser [T ]): () => Seq [T ]
53
53
54
54
/** Run `program` if all arguments are valid,
55
55
* or print usage information and/or error messages.
@@ -66,7 +66,7 @@ trait MainAnnotation extends StaticAnnotation:
66
66
inline def wrapperName (mainName : String ): String
67
67
68
68
/** An annotation type with which the wrapper method is decorated.
69
- * No annotation is generated of the type is left abstract.
69
+ * No annotation is generated if the type is left abstract.
70
70
*/
71
71
type WrapperAnnotation <: Annotation
72
72
@@ -115,7 +115,7 @@ class main extends MainAnnotation:
115
115
case Some (t) => () => t
116
116
case None => error(s " invalid argument for $argName: $arg" )
117
117
118
- def argGetter [T ](argName : String , p : ArgumentParser [T ], defaultValue : Option [T ] = None ): () => T =
118
+ def nextArgGetter [T ](argName : String , p : ArgumentParser [T ], defaultValue : Option [T ] = None ): () => T =
119
119
argInfos += ((argName, if defaultValue.isDefined then " ?" else " " ))
120
120
val idx = args.indexOf(s " -- $argName" )
121
121
val argOpt = if idx >= 0 then argAt(idx + 1 ) else nextPositionalArg()
@@ -125,7 +125,7 @@ class main extends MainAnnotation:
125
125
case Some (t) => () => t
126
126
case None => error(s " missing argument for $argName" )
127
127
128
- def argsGetter [T ](argName : String , p : ArgumentParser [T ]): () => Seq [T ] =
128
+ def finalArgsGetter [T ](argName : String , p : ArgumentParser [T ]): () => Seq [T ] =
129
129
argInfos += ((argName, " *" ))
130
130
def remainingArgGetters (): List [() => T ] = nextPositionalArg() match
131
131
case Some (arg) => convert(arg, argName, p) :: remainingArgGetters()
@@ -192,8 +192,8 @@ end myProgram
192
192
object add extends main :
193
193
@ EntryPoint def main (args : Array [String ]) =
194
194
val cmd = command(args)
195
- val arg1 = cmd.argGetter [Int ](" num" , summon[ArgumentParser [Int ]])
196
- val arg2 = cmd.argGetter [Int ](" inc" , summon[ArgumentParser [Int ]], Some (1 ))
195
+ val arg1 = cmd.nextArgGetter [Int ](" num" , summon[ArgumentParser [Int ]])
196
+ val arg2 = cmd.nextArgGetter [Int ](" inc" , summon[ArgumentParser [Int ]], Some (1 ))
197
197
cmd.run(myProgram.add(arg1(), arg2()), " add" , " Adds two numbers" )
198
198
end add
199
199
0 commit comments