From 646e2be126e6035ab776b7a84a61efc54356114a Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Wed, 25 Sep 2024 21:06:48 +0200 Subject: [PATCH] Ensure `--version` passed to the default command together with `--offline` doesn't look for the latest version online (#3207) --- .../scala/cli/commands/default/Default.scala | 10 +++++++++- .../scala/cli/integration/VersionTests.scala | 20 +++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/modules/cli/src/main/scala/scala/cli/commands/default/Default.scala b/modules/cli/src/main/scala/scala/cli/commands/default/Default.scala index 26b5dfc9c9..4f42a7ca3c 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/default/Default.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/default/Default.scala @@ -39,7 +39,15 @@ class Default(actualHelp: => RuntimeCommandsHelp) override def runCommand(options: DefaultOptions, args: RemainingArgs, logger: Logger): Unit = // can't fully re-parse and redirect to Version because of --cli-version and --scala-version clashing - if options.version then Version.runCommand(VersionOptions(options.shared.global), args, logger) + if options.version then + Version.runCommand( + options = VersionOptions( + global = options.shared.global, + offline = options.shared.coursier.getOffline().getOrElse(false) + ), + args = args, + logger = logger + ) else { val shouldDefaultToRun = diff --git a/modules/integration/src/test/scala/scala/cli/integration/VersionTests.scala b/modules/integration/src/test/scala/scala/cli/integration/VersionTests.scala index 880b59edc4..be186ddd18 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/VersionTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/VersionTests.scala @@ -5,18 +5,26 @@ import com.eed3si9n.expecty.Expecty.expect import scala.cli.integration.VersionTests.variants class VersionTests extends ScalaCliSuite { - test("version command") { - // tests if the format is correct instead of comparing to a version passed via Constants - // in order to catch errors in Mill configuration, too - val versionRegex = ".*\\d+[.]\\d+[.]\\d+.*".r - for (versionOption <- variants) { - val version = os.proc(TestUtil.cli, versionOption).call(check = false) + + for (versionOption <- variants) { + test(versionOption) { + // tests if the format is correct instead of comparing to a version passed via Constants + // in order to catch errors in Mill configuration, too + val versionRegex = ".*\\d+[.]\\d+[.]\\d+.*".r + val version = os.proc(TestUtil.cli, versionOption).call(check = false) assert( versionRegex.findFirstMatchIn(version.out.text()).isDefined, clues(version.exitCode, version.out.text(), version.err.text()) ) expect(version.exitCode == 0) } + + test(s"$versionOption --offline") { + TestInputs.empty.fromRoot { root => + // TODO: --power should not be necessary here + os.proc(TestUtil.cli, versionOption, "--offline", "--power").call(cwd = root) + } + } } }