Skip to content

Commit 72d1c9c

Browse files
Tweak error message when $SHELL is not set in 'install completions'
1 parent 0665afc commit 72d1c9c

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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,14 +38,12 @@ 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"))
35-
36-
val name = options.name.getOrElse {
37-
val baseName = (new Argv0).get("scala-cli")
38-
val idx = baseName.lastIndexOf(File.pathSeparator)
39-
if (idx < 0) baseName
40-
else baseName.drop(idx + 1)
41-
}
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+
}
4247

4348
val (rcScript, defaultRcFile) = format match {
4449
case Bash.id | "bash" =>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ 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,

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)