@@ -13,9 +13,17 @@ trait CliCommand:
1313
1414 type ConcreteSettings <: CommonScalaSettings with Settings .SettingGroup
1515
16+ def versionMsg : String
17+
18+ def ifErrorsMsg : String
19+
1620 /** The name of the command */
1721 def cmdName : String
1822
23+ def isHelpFlag (using settings : ConcreteSettings )(using SettingsState ): Boolean
24+
25+ def helpMsg (using settings : ConcreteSettings )(using SettingsState , Context ): String
26+
1927 private def explainAdvanced = """
2028 |-- Notes on option parsing --
2129 |Boolean settings are always false unless set.
@@ -31,14 +39,6 @@ trait CliCommand:
3139 | already are in phase X + 1.
3240 """
3341
34- def shortUsage : String = s " Usage: $cmdName <options> <source files> "
35-
36- def versionMsg : String = s " Scala $versionString -- $copyrightString"
37-
38- def ifErrorsMsg : String = " -help gives more information"
39-
40- def shouldStopWithInfo (using settings : ConcreteSettings )(using SettingsState ): Boolean
41-
4242 /** Distill arguments into summary detailing settings, errors and files to main */
4343 def distill (args : Array [String ], sg : Settings .SettingGroup , ss : SettingsState ): ArgsSummary =
4444 /**
@@ -64,11 +64,8 @@ trait CliCommand:
6464
6565 sg.processArguments(expandedArguments, ss, processAll = true )
6666
67-
68- def infoMessage (using settings : ConcreteSettings )(using SettingsState )(using Context ): String
69-
7067 /** Creates a help message for a subset of options based on cond */
71- def availableOptionsMsg (cond : Setting [? ] => Boolean )(using settings : ConcreteSettings )(using SettingsState ): String =
68+ protected def availableOptionsMsg (cond : Setting [? ] => Boolean )(using settings : ConcreteSettings )(using SettingsState ): String =
7269 val ss = (settings.allSettings filter cond).toList sortBy (_.name)
7370 val width = (ss map (_.name.length)).max
7471 def format (s : String ) = (" %-" + width + " s" ) format s
@@ -90,8 +87,9 @@ trait CliCommand:
9087
9188 ss.map(helpStr).mkString(" " , " \n " , s " \n ${format(" @<file>" )} A text file containing compiler arguments (options and source files). \n " )
9289
90+ protected def shortUsage : String = s " Usage: $cmdName <options> <source files> "
9391
94- def createUsageMsg (label : String , shouldExplain : Boolean , cond : Setting [? ] => Boolean )(using settings : ConcreteSettings )(using SettingsState ): String =
92+ protected def createUsageMsg (label : String , shouldExplain : Boolean , cond : Setting [? ] => Boolean )(using settings : ConcreteSettings )(using SettingsState ): String =
9593 val prefix = List (
9694 Some (shortUsage),
9795 Some (explainAdvanced) filter (_ => shouldExplain),
@@ -100,42 +98,50 @@ trait CliCommand:
10098
10199 prefix + " \n " + availableOptionsMsg(cond)
102100
103- def isStandard (s : Setting [? ])(using settings : ConcreteSettings )(using SettingsState ): Boolean = ! isAdvanced(s) && ! isPrivate(s)
104- def isAdvanced (s : Setting [? ])(using settings : ConcreteSettings )(using SettingsState ): Boolean = s.name.startsWith(" -X" ) && s.name != " -X"
105- def isPrivate (s : Setting [? ])(using settings : ConcreteSettings )(using SettingsState ): Boolean = s.name.startsWith(" -Y" ) && s.name != " -Y"
101+ protected def isStandard (s : Setting [? ])(using settings : ConcreteSettings )(using SettingsState ): Boolean =
102+ ! isAdvanced(s) && ! isPrivate(s)
103+ protected def isAdvanced (s : Setting [? ])(using settings : ConcreteSettings )(using SettingsState ): Boolean =
104+ s.name.startsWith(" -X" ) && s.name != " -X"
105+ protected def isPrivate (s : Setting [? ])(using settings : ConcreteSettings )(using SettingsState ): Boolean =
106+ s.name.startsWith(" -Y" ) && s.name != " -Y"
106107
107108 /** Messages explaining usage and options */
108- def usageMessage (using settings : ConcreteSettings )(using SettingsState ) = createUsageMsg(" where possible standard" , shouldExplain = false , isStandard)
109- def xusageMessage (using settings : ConcreteSettings )(using SettingsState ) = createUsageMsg(" Possible advanced" , shouldExplain = true , isAdvanced)
110- def yusageMessage (using settings : ConcreteSettings )(using SettingsState ) = createUsageMsg(" Possible private" , shouldExplain = true , isPrivate)
111-
112- def phasesMessage : String =
109+ protected def usageMessage (using settings : ConcreteSettings )(using SettingsState ) =
110+ createUsageMsg(" where possible standard" , shouldExplain = false , isStandard)
111+ protected def xusageMessage (using settings : ConcreteSettings )(using SettingsState ) =
112+ createUsageMsg(" Possible advanced" , shouldExplain = true , isAdvanced)
113+ protected def yusageMessage (using settings : ConcreteSettings )(using SettingsState ) =
114+ createUsageMsg(" Possible private" , shouldExplain = true , isPrivate)
115+
116+ protected def phasesMessage : String =
113117 (new Compiler ()).phases.map {
114118 case List (single) => single.phaseName
115119 case more => more.map(_.phaseName).mkString(" {" , " , " , " }" )
116120 }.mkString(" \n " )
117121
118122 /** Provide usage feedback on argument summary, assuming that all settings
119123 * are already applied in context.
120- * @return The list of files passed as arguments.
124+ * @return Either Some list of files passed as arguments or None if further processing should be interrupted .
121125 */
122- def checkUsage (summary : ArgsSummary , sourcesRequired : Boolean )(using settings : ConcreteSettings )(using SettingsState )( using Context ): List [String ] =
126+ def checkUsage (summary : ArgsSummary , sourcesRequired : Boolean )(using settings : ConcreteSettings )(using SettingsState , Context ): Option [ List [String ] ] =
123127 // Print all warnings encountered during arguments parsing
124128 summary.warnings.foreach(report.warning(_))
125129
126130 if summary.errors.nonEmpty then
127131 summary.errors foreach (report.error(_))
128132 report.echo(ifErrorsMsg)
129- Nil
133+ None
130134 else if settings.version.value then
131135 report.echo(versionMsg)
132- Nil
133- else if shouldStopWithInfo then
134- report.echo(infoMessage)
135- Nil
136+ None
137+ else if isHelpFlag then
138+ report.echo(helpMsg)
139+ None
140+ else if (sourcesRequired && summary.arguments.isEmpty)
141+ report.echo(usageMessage)
142+ None
136143 else
137- if (sourcesRequired && summary.arguments.isEmpty) report.echo(usageMessage)
138- summary.arguments
144+ Some (summary.arguments)
139145
140146 extension [T ](setting : Setting [T ])
141147 protected def value (using ss : SettingsState ): T = setting.valueIn(ss)
0 commit comments