Skip to content

Commit 1167e82

Browse files
Merge pull request #93 from alexarchambault/develop
Tweak things in installation instructions and completion
2 parents d1f8fa6 + 72d1c9c commit 1167e82

File tree

6 files changed

+40
-13
lines changed

6 files changed

+40
-13
lines changed

modules/cli-core/src/main/scala/scala/cli/ScalaCliBase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class ScalaCliBase extends CommandsEntryPoint {
1111

1212
def actualDefaultCommand: DefaultBase
1313

14-
lazy val progName = (new Argv0).get("scala")
14+
lazy val progName = (new Argv0).get("scala-cli")
1515
override def description = "Compile, run, package Scala code."
1616
final override def defaultCommand = Some(actualDefaultCommand)
1717

modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletions.scala

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.util.Arrays
77
import caseapp._
88
import caseapp.core.complete.{Bash, Zsh}
99

10-
import scala.cli.internal.ProfileFileUpdater
10+
import scala.cli.internal.{Argv0, ProfileFileUpdater}
1111

1212
object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
1313
override def names = List(
@@ -23,6 +23,13 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
2323

2424
val logger = options.logging.logger
2525

26+
val name = options.name.getOrElse {
27+
val baseName = (new Argv0).get("scala-cli")
28+
val idx = baseName.lastIndexOf(File.pathSeparator)
29+
if (idx < 0) baseName
30+
else baseName.drop(idx + 1)
31+
}
32+
2633
val format = options.format.map(_.trim).filter(_.nonEmpty)
2734
.orElse {
2835
Option(System.getenv("SHELL")).map(_.split(File.separator).last).map {
@@ -31,21 +38,26 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
3138
case other => other
3239
}
3340
}
34-
.getOrElse(sys.error("Cannot determine current shell, pass the shell you use with --format"))
41+
.getOrElse {
42+
System.err.println("Cannot determine current shell, pass the shell you use with --shell, like")
43+
System.err.println(s" $name install completions --shell zsh")
44+
System.err.println(s" $name install completions --shell bash")
45+
sys.exit(1)
46+
}
3547

3648
val (rcScript, defaultRcFile) = format match {
3749
case Bash.id | "bash" =>
38-
val script = Bash.script(options.name)
50+
val script = Bash.script(name)
3951
val defaultRcFile = home / ".bashrc"
4052
(script, defaultRcFile)
4153
case Zsh.id | "zsh" =>
42-
val completionScript = Zsh.script(options.name)
54+
val completionScript = Zsh.script(name)
4355
val zDotDir = Option(System.getenv("ZDOTDIR"))
4456
.map(os.Path(_, os.pwd))
4557
.getOrElse(home)
4658
val defaultRcFile = zDotDir / ".zshrc"
4759
val dir = completionsDir / "zsh"
48-
val completionScriptDest = dir / "_scala"
60+
val completionScriptDest = dir / s"_$name"
4961
val content = completionScript.getBytes(Charset.defaultCharset())
5062
if (!os.exists(completionScriptDest) || !Arrays.equals(os.read.bytes(completionScriptDest), content)) {
5163
logger.log(s"Writing $completionScriptDest")
@@ -65,7 +77,7 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
6577
.map(os.Path(_, os.pwd))
6678
.getOrElse(defaultRcFile)
6779

68-
val banner = options.banner.replace("{NAME}", options.name)
80+
val banner = options.banner.replace("{NAME}", name)
6981

7082
val updated = ProfileFileUpdater.addToProfileFile(rcFile.toNIO, banner, rcScript, Charset.defaultCharset())
7183

modules/cli-core/src/main/scala/scala/cli/commands/InstallCompletionsOptions.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ final case class InstallCompletionsOptions(
88
@Recurse
99
directories: SharedDirectoriesOptions = SharedDirectoriesOptions(),
1010

11-
format: Option[String] = None,
11+
@Name("shell")
12+
format: Option[String] = None,
1213

1314
rcFile: Option[String] = None,
1415
directory: Option[String] = None,
15-
banner: String = "{NAME} CLI completions",
16-
name: String = "scala"
16+
banner: String = "{NAME} completions",
17+
name: Option[String] = None
1718
)

project/settings.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ trait CliLaunchers extends SbtModule { self =>
7171
def nativeImageOptions = Seq(
7272
s"-H:IncludeResources=$localRepoResourcePath"
7373
)
74-
def nativeImageName = "scala"
74+
def nativeImageName = "scala-cli"
7575
def nativeImageClassPath = self.nativeImageClassPath()
7676
def nativeImageMainClass = self.nativeImageMainClass()
7777
}

website/docs/installation.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Download the launcher from GitHub release assets with
2929
```text
3030
$ curl -fL https://github.com/VirtuslabRnD/scala-cli/releases/download/nightly/scala-cli-x86_64-apple-darwin.gz | gzip -d > scala-cli
3131
$ chmod +x scala-cli
32-
$ sudo mv scala-cli /usr/local/bin/scala-cli
32+
$ mv scala-cli /usr/local/bin/scala-cli
3333
```
3434

3535
Check that it runs fine by running its `about` command:
@@ -39,6 +39,9 @@ $ scala-cli about
3939

4040
### Windows
4141

42+
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)
43+
to be installed. See below for how to install it.
44+
4245
Download the launcher from GitHub release assets with
4346
```text
4447
> 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:
5053
> scala-cli about
5154
```
5255

53-
Note that this doesn't put the `scala-cli` command in the `PATH`. For that, you can create a directory, move the
56+
If you get an error about `MSVCR100.dll` being missing, you have to install
57+
[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.
58+
You can download it [here](https://github.com/VirtuslabRnD/scala-cli/releases/download/nightly/vc_redist.x64.exe),
59+
and install it by double-clicking on it. Once the Visual C++ redistributable runtime is installed,
60+
check that the Scala CLI runs fine by running its `about` command:
61+
```text
62+
> scala-cli about
63+
```
64+
65+
Note that the commands above don't put the `scala-cli` command in the `PATH`. For that, you can create a directory, move the
5466
launcher there, and add the directory to the `PATH` with
5567
```text
5668
> md "%USERPROFILE%/scala-cli"

website/docs/reference/cli-options.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ Available in commands:
163163

164164
#### `--format`
165165

166+
Aliases: `--shell`
167+
166168
#### `--rc-file`
167169

168170
#### `--directory`

0 commit comments

Comments
 (0)