Skip to content

Commit 646e2be

Browse files
authored
Ensure --version passed to the default command together with --offline doesn't look for the latest version online (#3207)
1 parent 68b3ce8 commit 646e2be

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

modules/cli/src/main/scala/scala/cli/commands/default/Default.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ class Default(actualHelp: => RuntimeCommandsHelp)
3939

4040
override def runCommand(options: DefaultOptions, args: RemainingArgs, logger: Logger): Unit =
4141
// can't fully re-parse and redirect to Version because of --cli-version and --scala-version clashing
42-
if options.version then Version.runCommand(VersionOptions(options.shared.global), args, logger)
42+
if options.version then
43+
Version.runCommand(
44+
options = VersionOptions(
45+
global = options.shared.global,
46+
offline = options.shared.coursier.getOffline().getOrElse(false)
47+
),
48+
args = args,
49+
logger = logger
50+
)
4351
else
4452
{
4553
val shouldDefaultToRun =

modules/integration/src/test/scala/scala/cli/integration/VersionTests.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@ import com.eed3si9n.expecty.Expecty.expect
55
import scala.cli.integration.VersionTests.variants
66

77
class VersionTests extends ScalaCliSuite {
8-
test("version command") {
9-
// tests if the format is correct instead of comparing to a version passed via Constants
10-
// in order to catch errors in Mill configuration, too
11-
val versionRegex = ".*\\d+[.]\\d+[.]\\d+.*".r
12-
for (versionOption <- variants) {
13-
val version = os.proc(TestUtil.cli, versionOption).call(check = false)
8+
9+
for (versionOption <- variants) {
10+
test(versionOption) {
11+
// tests if the format is correct instead of comparing to a version passed via Constants
12+
// in order to catch errors in Mill configuration, too
13+
val versionRegex = ".*\\d+[.]\\d+[.]\\d+.*".r
14+
val version = os.proc(TestUtil.cli, versionOption).call(check = false)
1415
assert(
1516
versionRegex.findFirstMatchIn(version.out.text()).isDefined,
1617
clues(version.exitCode, version.out.text(), version.err.text())
1718
)
1819
expect(version.exitCode == 0)
1920
}
21+
22+
test(s"$versionOption --offline") {
23+
TestInputs.empty.fromRoot { root =>
24+
// TODO: --power should not be necessary here
25+
os.proc(TestUtil.cli, versionOption, "--offline", "--power").call(cwd = root)
26+
}
27+
}
2028
}
2129

2230
}

0 commit comments

Comments
 (0)