-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalized configuration to work on groups too: #78
- Loading branch information
Showing
3 changed files
with
170 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.github.vigoo.prox | ||
|
||
import java.nio.file.Path | ||
|
||
/** Common base trait for processes and process groups, used in constraints in the redirection traits */ | ||
trait ProcessLike[F[_]] | ||
|
||
trait ProcessLikeConfiguration[F[_]] { | ||
val workingDirectory: Option[Path] | ||
val environmentVariables: Map[String, String] | ||
val removedEnvironmentVariables: Set[String] | ||
|
||
type Self <: ProcessLikeConfiguration[F] | ||
|
||
protected def applyConfiguration(workingDirectory: Option[Path], | ||
environmentVariables: Map[String, String], | ||
removedEnvironmentVariables: Set[String]): Self | ||
|
||
/** | ||
* Changes the working directory of the process | ||
* @param workingDirectory the working directory | ||
* @return a new process with the working directory set | ||
*/ | ||
def in(workingDirectory: Path): Self = | ||
applyConfiguration(workingDirectory = Some(workingDirectory), environmentVariables, removedEnvironmentVariables) | ||
|
||
/** | ||
* Use the inherited working directory of the process instead of an explicit one | ||
* @return a new process with the working directory cleared | ||
*/ | ||
def inInheritedWorkingDirectory(): Self = | ||
applyConfiguration(workingDirectory = None, environmentVariables, removedEnvironmentVariables) | ||
|
||
/** | ||
* Adds an environment variable to the process | ||
* @param nameValuePair A pair of name and value | ||
* @return a new process with the working directory set | ||
*/ | ||
def `with`(nameValuePair: (String, String)): Self = | ||
applyConfiguration(workingDirectory, environmentVariables = environmentVariables + nameValuePair, removedEnvironmentVariables) | ||
|
||
/** | ||
* Removes an environment variable from the process | ||
* | ||
* Usable to remove variables inherited from the parent process. | ||
* | ||
* @param name Name of the environment variable | ||
* @return a new process with the working directory set | ||
*/ | ||
def without(name: String): Self = | ||
applyConfiguration(workingDirectory, environmentVariables, removedEnvironmentVariables = removedEnvironmentVariables + name) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.