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) 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..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 @@ -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( @@ -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,21 +38,26 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] { case other => other } } - .getOrElse(sys.error("Cannot determine current shell, pass the shell you use with --format")) + .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" => - 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) 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") @@ -65,7 +77,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..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,10 +8,11 @@ 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, - banner: String = "{NAME} CLI completions", - name: String = "scala" + banner: String = "{NAME} completions", + name: Option[String] = None ) 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() } diff --git a/website/docs/installation.md b/website/docs/installation.md index 27b10edb85..c209a4ac65 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: @@ -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" 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`