Skip to content

Commit

Permalink
Make syntax scala-2 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
natsukagami committed Jun 4, 2024
1 parent 2c2810e commit b5179f6
Showing 1 changed file with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,26 @@ object PlatformCommandsMethods {
options: PlatformCommandsMethods.CompletionsInstallOptions,
progName: String,
installCompletionsCommand: String,
printLine: (message: String, toStderr: Boolean) => Unit,
exit: (code: Int) => Nothing
/* (message: String, toStderr: Boolean) => Unit */
printLine: (String, Boolean) => Unit,
/* (code: Int) */
exit: Int => Nothing
): Unit = {
lazy val completionsDir = Paths.get(options.output.getOrElse(completionsWorkingDirectory))

val name = options.name.getOrElse(Paths.get(progName).getFileName.toString)
val format = PlatformCommandsMethods.getFormat(options.format).getOrElse {
printLine(
"Cannot determine current shell, pass the shell you use with --shell, like",
toStderr = true
true
)
printLine("", toStderr = true)
printLine("", true)
for (shell <- Seq(Bash.shellName, Zsh.shellName, Fish.shellName))
printLine(
s" $name $installCompletionsCommand --shell $shell",
toStderr = true
true
)
printLine("", toStderr = true)
printLine("", true)
exit(1)
}

Expand Down Expand Up @@ -118,7 +120,7 @@ object PlatformCommandsMethods {
val needsWrite = !Files.exists(completionScriptDest) ||
!Arrays.equals(Files.readAllBytes(completionScriptDest), content)
if (needsWrite) {
printLine(s"Writing $completionScriptDest", toStderr = false)
printLine(s"Writing $completionScriptDest", false)
Files.createDirectories(completionScriptDest.getParent)
Files.write(completionScriptDest, content)
}
Expand All @@ -128,7 +130,7 @@ object PlatformCommandsMethods {
).map(_ + System.lineSeparator()).mkString
(script, defaultRcFile)
case _ =>
printLine(s"Unrecognized or unsupported shell: $format", toStderr = true)
printLine(s"Unrecognized or unsupported shell: $format", true)
exit(1)
}

Expand All @@ -153,29 +155,29 @@ object PlatformCommandsMethods {
val evalCommand =
s"eval $q$$($progName $installCompletionsCommand --env)$q"
if (updated) {
printLine(s"Updated $rcFile", toStderr = true)
printLine("", toStderr = true)
printLine(s"Updated $rcFile", true)
printLine("", true)
printLine(
s"It is recommended to reload your shell, or source $rcFile in the " +
"current session, for its changes to be taken into account.",
toStderr = true
true
)
printLine("", toStderr = true)
printLine("", true)
printLine(
"Alternatively, enable completions in the current session with",
toStderr = true
true
)
printLine("", toStderr = true)
printLine(s" $evalCommand", toStderr = true)
printLine("", toStderr = true)
printLine("", true)
printLine(s" $evalCommand", true)
printLine("", true)
}
else {
printLine(s"$rcFile already up-to-date.", toStderr = true)
printLine("", toStderr = true)
printLine("If needed, enable completions in the current session with", toStderr = true)
printLine("", toStderr = true)
printLine(s" $evalCommand", toStderr = true)
printLine("", toStderr = true)
printLine(s"$rcFile already up-to-date.", true)
printLine("", true)
printLine("If needed, enable completions in the current session with", true)
printLine("", true)
printLine(s" $evalCommand", true)
printLine("", true)
}
}
}
Expand All @@ -184,7 +186,8 @@ object PlatformCommandsMethods {
completionsWorkingDirectory: String,
options: PlatformCommandsMethods.CompletionsUninstallOptions,
progName: String,
printLine: (message: String, toStderr: Boolean) => Unit
/* (message: String, toStderr: Boolean) => Unit */
printLine: (String, Boolean) => Unit
): Unit = {
val name = options.name.getOrElse(Paths.get(progName).getFileName.toString)

Expand All @@ -210,11 +213,11 @@ object PlatformCommandsMethods {
)

if (updated) {
printLine(s"Updated $rcFile", toStderr = true)
printLine(s"$name completions uninstalled successfully", toStderr = true)
printLine(s"Updated $rcFile", true)
printLine(s"$name completions uninstalled successfully", true)
}
else
printLine(s"No $name completion section found in $rcFile", toStderr = true)
printLine(s"No $name completion section found in $rcFile", true)
}
}

Expand Down

0 comments on commit b5179f6

Please sign in to comment.