From 13fba0b215c298ac6db4aa853e4e282b5e25524b Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 16 Aug 2021 10:48:16 +0200 Subject: [PATCH 1/7] Use argv0 in completion script Useful if the CLI is installed under a different name - the actual name should get automatically picked via argv[0]. --- .../scala/cli/commands/InstallCompletions.scala | 15 +++++++++++---- .../cli/commands/InstallCompletionsOptions.scala | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala index f830bcc06a..cf523036d6 100644 --- a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala +++ b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala @@ -7,7 +7,7 @@ import java.util.Arrays import caseapp._ import caseapp.core.complete.{Bash, Zsh} -import scala.cli.internal.ProfileFileUpdater +import scala.cli.internal.{Argv0, ProfileFileUpdater} object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] { override def names = List( @@ -33,13 +33,20 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] { } .getOrElse(sys.error("Cannot determine current shell, pass the shell you use with --format")) + val name = options.name.getOrElse { + val baseName = (new Argv0).get("scala-cli") + val idx = baseName.lastIndexOf(File.pathSeparator) + if (idx < 0) baseName + else baseName.drop(idx + 1) + } + val (rcScript, defaultRcFile) = format match { case Bash.id | "bash" => - val script = Bash.script(options.name) + val script = Bash.script(name) val defaultRcFile = home / ".bashrc" (script, defaultRcFile) case Zsh.id | "zsh" => - val completionScript = Zsh.script(options.name) + val completionScript = Zsh.script(name) val zDotDir = Option(System.getenv("ZDOTDIR")) .map(os.Path(_, os.pwd)) .getOrElse(home) @@ -65,7 +72,7 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] { .map(os.Path(_, os.pwd)) .getOrElse(defaultRcFile) - val banner = options.banner.replace("{NAME}", options.name) + val banner = options.banner.replace("{NAME}", name) val updated = ProfileFileUpdater.addToProfileFile(rcFile.toNIO, banner, rcScript, Charset.defaultCharset()) diff --git a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala index d9b7c4c49d..b1415e6bfe 100644 --- a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala +++ b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala @@ -12,6 +12,6 @@ final case class InstallCompletionsOptions( rcFile: Option[String] = None, directory: Option[String] = None, - banner: String = "{NAME} CLI completions", - name: String = "scala" + banner: String = "{NAME} completions", + name: Option[String] = None ) From 863bd27dcee7ad63f480ce9668820b6084dd12c2 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 16 Aug 2021 10:49:53 +0200 Subject: [PATCH 2/7] Use scala-cli as name during native-image in build --- project/settings.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/settings.sc b/project/settings.sc index a4e5edb3da..da2f700c0a 100644 --- a/project/settings.sc +++ b/project/settings.sc @@ -71,7 +71,7 @@ trait CliLaunchers extends SbtModule { self => def nativeImageOptions = Seq( s"-H:IncludeResources=$localRepoResourcePath" ) - def nativeImageName = "scala" + def nativeImageName = "scala-cli" def nativeImageClassPath = self.nativeImageClassPath() def nativeImageMainClass = self.nativeImageMainClass() } From 084359d068df69af4176925a759009ed74412804 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 16 Aug 2021 10:50:17 +0200 Subject: [PATCH 3/7] Don't use sudo in macOS installation instructions Seems it's not required to write in /usr/local/bin --- website/docs/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/installation.md b/website/docs/installation.md index 27b10edb85..bf2ab33577 100644 --- a/website/docs/installation.md +++ b/website/docs/installation.md @@ -29,7 +29,7 @@ Download the launcher from GitHub release assets with ```text $ curl -fL https://github.com/VirtuslabRnD/scala-cli/releases/download/nightly/scala-cli-x86_64-apple-darwin.gz | gzip -d > scala-cli $ chmod +x scala-cli -$ sudo mv scala-cli /usr/local/bin/scala-cli +$ mv scala-cli /usr/local/bin/scala-cli ``` Check that it runs fine by running its `about` command: From ae3c8cab85dd01578370514c2d1260683f39c151 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 16 Aug 2021 10:51:22 +0200 Subject: [PATCH 4/7] Add Visual C++ redist instructions in install page --- website/docs/installation.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/website/docs/installation.md b/website/docs/installation.md index bf2ab33577..c209a4ac65 100644 --- a/website/docs/installation.md +++ b/website/docs/installation.md @@ -39,6 +39,9 @@ $ scala-cli about ### Windows +Note that the Windows manual installation requires [Visual C++ redistributable](https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0) +to be installed. See below for how to install it. + Download the launcher from GitHub release assets with ```text > curl -fLo scala-cli.zip https://github.com/VirtuslabRnD/scala-cli/releases/download/nightly/scala-cli-x86_64-pc-win32.zip @@ -50,7 +53,16 @@ Check that it runs fine by running its `about` command: > scala-cli about ``` -Note that this doesn't put the `scala-cli` command in the `PATH`. For that, you can create a directory, move the +If you get an error about `MSVCR100.dll` being missing, you have to install +[Visual C++ redistributable](https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0). A valid version is distributed with the Scala CLI launchers. +You can download it [here](https://github.com/VirtuslabRnD/scala-cli/releases/download/nightly/vc_redist.x64.exe), +and install it by double-clicking on it. Once the Visual C++ redistributable runtime is installed, +check that the Scala CLI runs fine by running its `about` command: +```text +> scala-cli about +``` + +Note that the commands above don't put the `scala-cli` command in the `PATH`. For that, you can create a directory, move the launcher there, and add the directory to the `PATH` with ```text > md "%USERPROFILE%/scala-cli" From d7a2c21b7454de6516f17c94cc4176ac28e102f9 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 16 Aug 2021 11:30:07 +0200 Subject: [PATCH 5/7] Adjust default command name --- modules/cli-core/src/main/scala/scala/cli/ScalaCliBase.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cli-core/src/main/scala/scala/cli/ScalaCliBase.scala b/modules/cli-core/src/main/scala/scala/cli/ScalaCliBase.scala index e8ba0c497b..56433ff607 100644 --- a/modules/cli-core/src/main/scala/scala/cli/ScalaCliBase.scala +++ b/modules/cli-core/src/main/scala/scala/cli/ScalaCliBase.scala @@ -11,7 +11,7 @@ abstract class ScalaCliBase extends CommandsEntryPoint { def actualDefaultCommand: DefaultBase - lazy val progName = (new Argv0).get("scala") + lazy val progName = (new Argv0).get("scala-cli") override def description = "Compile, run, package Scala code." final override def defaultCommand = Some(actualDefaultCommand) From 0665afce40ae402135f2ccfd2ebccb2ac54e3193 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 16 Aug 2021 11:37:15 +0200 Subject: [PATCH 6/7] Fix zsh completion script name --- .../src/main/scala/scala/cli/commands/InstallCompletions.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala index cf523036d6..5cfcce7f24 100644 --- a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala +++ b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala @@ -52,7 +52,7 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] { .getOrElse(home) val defaultRcFile = zDotDir / ".zshrc" val dir = completionsDir / "zsh" - val completionScriptDest = dir / "_scala" + val completionScriptDest = dir / s"_$name" val content = completionScript.getBytes(Charset.defaultCharset()) if (!os.exists(completionScriptDest) || !Arrays.equals(os.read.bytes(completionScriptDest), content)) { logger.log(s"Writing $completionScriptDest") From 72d1c9c202a78011c0a5a9d8086c3a5a4f874733 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 16 Aug 2021 12:23:13 +0200 Subject: [PATCH 7/7] Tweak error message when $SHELL is not set in 'install completions' --- .../cli/commands/InstallCompletions.scala | 21 ++++++++++++------- .../commands/InstallCompletionsOptions.scala | 3 ++- website/docs/reference/cli-options.md | 2 ++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala index 5cfcce7f24..d8b41699a7 100644 --- a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala +++ b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala @@ -23,6 +23,13 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] { val logger = options.logging.logger + val name = options.name.getOrElse { + val baseName = (new Argv0).get("scala-cli") + val idx = baseName.lastIndexOf(File.pathSeparator) + if (idx < 0) baseName + else baseName.drop(idx + 1) + } + val format = options.format.map(_.trim).filter(_.nonEmpty) .orElse { Option(System.getenv("SHELL")).map(_.split(File.separator).last).map { @@ -31,14 +38,12 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] { case other => other } } - .getOrElse(sys.error("Cannot determine current shell, pass the shell you use with --format")) - - val name = options.name.getOrElse { - val baseName = (new Argv0).get("scala-cli") - val idx = baseName.lastIndexOf(File.pathSeparator) - if (idx < 0) baseName - else baseName.drop(idx + 1) - } + .getOrElse { + System.err.println("Cannot determine current shell, pass the shell you use with --shell, like") + System.err.println(s" $name install completions --shell zsh") + System.err.println(s" $name install completions --shell bash") + sys.exit(1) + } val (rcScript, defaultRcFile) = format match { case Bash.id | "bash" => diff --git a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala index b1415e6bfe..fe7373f9e9 100644 --- a/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala +++ b/modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala @@ -8,7 +8,8 @@ final case class InstallCompletionsOptions( @Recurse directories: SharedDirectoriesOptions = SharedDirectoriesOptions(), - format: Option[String] = None, + @Name("shell") + format: Option[String] = None, rcFile: Option[String] = None, directory: Option[String] = None, diff --git a/website/docs/reference/cli-options.md b/website/docs/reference/cli-options.md index 2e75fb347d..9982dd0d9e 100644 --- a/website/docs/reference/cli-options.md +++ b/website/docs/reference/cli-options.md @@ -163,6 +163,8 @@ Available in commands: #### `--format` +Aliases: `--shell` + #### `--rc-file` #### `--directory`