New main annotation design #14977
Replies: 7 comments 8 replies
-
Named argumentsThe main annotation supports named arguments. The question is which is the format of a name. Option 1 (current design)The current design provides long and short names based
Parameters with a name with a single character expect a short name argument and parameters with more than one character expect a long name argument. Note that we want to interpret names starting with Option 2Do not have named arguments. Consider this an advanced use case that another implementation can add. |
Beta Was this translation helpful? Give feedback.
-
AliasesOption 1 (current design)Have an @newMain def f(@alias("i") input: String): Unit = ... This main method can be called as with arguments The named arguments rules apply to aliases. Option 2Do not support aliases. They might not be needed as much as we would think. Another main annotation implementation could exist with advanced support for parameter aliasing. Aliases introduce some overhead at runtime and complexity in the implementation. These could be avoided. |
Beta Was this translation helpful? Give feedback.
-
Named argument escapeThe idea is to have a way to pass
For example in Current designWe add the |
Beta Was this translation helpful? Give feedback.
-
Argument parsersParsers are used to convert the string argument into a value of some type. Current designWe use Currently, this provides parsers for
|
Beta Was this translation helpful? Give feedback.
-
FlagsFlags are optional named parameters with no argument values. For example
Option 1Have a
With this design, we can still have an unannotated boolean parameter that can receive Option 2 (current design)Make all boolean parameters flag parameters.
With this design, we cannot have boolean parameters that can receive Option 3Do not support flags. Consider this an advanced use case that another implementation can add. |
Beta Was this translation helpful? Give feedback.
-
Default helpThe idea is to generate a default help message if the main is called with Option 1 (current design)Print default help message if Option 2Print default help message if Option 3Do not provide help. |
Beta Was this translation helpful? Give feedback.
-
Compound flagsWe could extend the design of #14977 (comment) to support compound flags |
Beta Was this translation helpful? Give feedback.
-
We are in the process of improving the
@main
annotation using the main annotation generalizationscala.annotation.MainAnnotation
. The current prototype can be found in #14841 asscala.annotation.newMain
/@newMain
.The aim of this main annotation is to be simple to use out of the box. Easy for newcomers and have some degree of flexibility for more advanced use cases. Libraries/applications that want advanced customization of main annotations can implement their own
MainAnnotation
.Note that we will merge #14841 even if it is not the final design. This will allow you to test it and provide concrete feedback (bugs or design suggestions).
This discussion section will split different pieces of the design into separate sub-discussions.
Beta Was this translation helpful? Give feedback.
All reactions