Skip to content

Commit 1196ceb

Browse files
committed
More unification, fixed test
1 parent 2117442 commit 1196ceb

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

compiler/src/dotty/tools/dotc/config/Settings.scala

+15-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ object Settings:
170170
case (StringTag, arg2 :: args2) =>
171171
if (arg2 startsWith "-") missingArg
172172
else setString(arg2, args2)
173+
case (OutputTag, _) if argRest.nonEmpty =>
174+
val path = Directory(argRest)
175+
val isJar = path.extension == "jar"
176+
if (!isJar && !path.isDirectory)
177+
fail(s"'$argRest' does not exist or is not a directory or .jar file", args)
178+
else {
179+
val output = if (isJar) JarArchive.create(path) else new PlainDirectory(path)
180+
update(output, args)
181+
}
173182
case (OutputTag, arg :: args) =>
174183
val path = Directory(arg)
175184
val isJar = path.extension == "jar"
@@ -183,11 +192,16 @@ object Settings:
183192
setInt(argRest, args)
184193
case (IntTag, arg2 :: args2) =>
185194
setInt(arg2, args2)
186-
case (VersionTag, _) =>
195+
case (VersionTag, _) if argRest.nonEmpty =>
187196
ScalaVersion.parse(argRest) match {
188197
case Success(v) => update(v, args)
189198
case Failure(ex) => fail(ex.getMessage, args)
190199
}
200+
case (VersionTag, arg2 :: args2) =>
201+
ScalaVersion.parse(arg2) match {
202+
case Success(v) => update(v, args2)
203+
case Failure(ex) => fail(ex.getMessage, args2)
204+
}
191205
case (_, Nil) =>
192206
missingArg
193207
}

compiler/test/dotty/tools/dotc/SettingsTests.scala

+11-11
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class SettingsTests {
8787

8888
@Test def `bad option warning consumes an arg`: Unit =
8989
object Settings extends SettingGroup:
90-
val option = BooleanSetting("", "-option", "Some option")
90+
val option = BooleanSetting("", "option", "Some option")
9191

9292
val args = List("-adoption", "dogs", "cats")
9393
val summary = Settings.processArguments(args, processAll = true)
@@ -97,7 +97,7 @@ class SettingsTests {
9797

9898
@Test def `bad option settings throws`: Unit =
9999
object Settings extends SettingGroup:
100-
val option = BooleanSetting("", "-option", "Some option")
100+
val option = BooleanSetting("", "option", "Some option")
101101

102102
def checkMessage(s: String): (Throwable => Boolean) = t =>
103103
if t.getMessage == s then true
@@ -112,12 +112,12 @@ class SettingsTests {
112112

113113
@Test def validateChoices: Unit =
114114
object Settings extends SettingGroup:
115-
val foo = ChoiceSetting("", "-foo", "foo", "Foo", List("a", "b"), "a")
116-
val bar = IntChoiceSetting("", "-bar", "Bar", List(0, 1, 2), 0)
117-
val baz = IntChoiceSetting("", "-baz", "Baz", 0 to 10, 10)
115+
val foo = ChoiceSetting("", "foo", "foo", "Foo", List("a", "b"), "a")
116+
val bar = IntChoiceSetting("", "bar", "Bar", List(0, 1, 2), 0)
117+
val baz = IntChoiceSetting("", "baz", "Baz", 0 to 10, 10)
118118

119-
val quux = ChoiceSetting("", "-quux", "quux", "Quux", List(), "")
120-
val quuz = IntChoiceSetting("", "-quuz", "Quuz", List(), 0)
119+
val quux = ChoiceSetting("", "quux", "quux", "Quux", List(), "")
120+
val quuz = IntChoiceSetting("", "quuz", "Quuz", List(), 0)
121121

122122
locally {
123123
val args = List("-foo", "b", "-bar", "1", "-baz", "5")
@@ -181,10 +181,10 @@ class SettingsTests {
181181

182182
@Test def `Set BooleanSettings correctly`: Unit =
183183
object Settings extends SettingGroup:
184-
val foo = BooleanSetting("", "-foo", "foo", false)
185-
val bar = BooleanSetting("", "-bar", "bar", true)
186-
val baz = BooleanSetting("", "-baz", "baz", false)
187-
val qux = BooleanSetting("", "-qux", "qux", false)
184+
val foo = BooleanSetting("", "foo", "foo", false)
185+
val bar = BooleanSetting("", "bar", "bar", true)
186+
val baz = BooleanSetting("", "baz", "baz", false)
187+
val qux = BooleanSetting("", "qux", "qux", false)
188188
import Settings._
189189

190190
val args = List("-foo:true", "-bar:false", "-baz", "-qux:true", "-qux:false")

0 commit comments

Comments
 (0)