All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.cli.commands.addpath.AddPath.scala Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package scala.cli.commands.addpath

import caseapp.*
import coursier.env.{EnvironmentUpdate, ProfileUpdater}

import java.io.File

import scala.build.Logger
import scala.build.internals.EnvVar
import scala.cli.CurrentParams
import scala.cli.commands.{CustomWindowsEnvVarUpdater, ScalaCommand}
import scala.util.Properties

object AddPath extends ScalaCommand[AddPathOptions] {
  override def hidden                  = true
  override def scalaSpecificationLevel = SpecificationLevel.RESTRICTED
  override def runCommand(options: AddPathOptions, args: RemainingArgs, logger: Logger): Unit = {
    if args.all.isEmpty then logger.error("Nothing to do")
    else {
      val update = EnvironmentUpdate(
        Nil,
        Seq(EnvVar.Misc.path.name -> args.all.mkString(File.pathSeparator))
      )
      val didUpdate =
        if (Properties.isWin) {
          val updater = CustomWindowsEnvVarUpdater().withUseJni(Some(coursier.paths.Util.useJni()))
          updater.applyUpdate(update)
        }
        else {
          val updater = ProfileUpdater()
          updater.applyUpdate(update, Some(options.title).filter(_.nonEmpty))
        }
      if !didUpdate then logger.log("Everything up-to-date")
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy