Skip to content

Commit

Permalink
Adding PAKET_VERSION posix compliant environment variable for bootstr…
Browse files Browse the repository at this point in the history
…apper
  • Loading branch information
Jimmy Byrd committed Oct 20, 2017
1 parent 12d8494 commit 7c5e3eb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
22 changes: 21 additions & 1 deletion docs/content/bootstrapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,23 @@ Example:

### With environment variables

`PAKET.VERSION`: The requested version can also be set using this environment
`PAKET_VERSION`: The requested version can also be set using this environment
variable.

* powershell
```
$env:PAKET_VERSION = "5.119.7"
```
* cmd
```
set PAKET_VERSION "5.119.7"
```
* bash
```
export PAKET_VERSION="5.119.7"
```
### In paket.dependencies
If a [`paket.dependencies` file](dependencies-file.html) is found in the current
Expand Down Expand Up @@ -146,3 +160,9 @@ A few default settings are applied:
* The bootstrapper is silenced and only errors are displayed. `-v` can be used
once to restore normal output or twice to show more details.
* If no version is specified a default `--max-file-age` of `12` hours is used.

### Setting version in magic mode

You can use the [settings listed above](#In-application-settings) but now `paket.bootstrapper.exe.config` becomes `paket.exe.config`


5 changes: 4 additions & 1 deletion src/Paket.Bootstrapper/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public static class AppSettingKeys
public static class EnvArgs
{
public const string PaketVersionEnv = "PAKET.VERSION";
// Posix compliant environment variables [a-zA-Z_]+[a-zA-Z0-9_]*
// As to not break backwards compatability just adding a second env var
public const string PaketVersionEnvPosix = "PAKET_VERSION";
}

private static void FillTarget(DownloadArguments downloadArguments, bool magicMode, IFileSystemProxy fileSystem)
Expand Down Expand Up @@ -147,7 +150,7 @@ private static void FillOptionsFromAppSettings(BootstrapperOptions options, Name

private static void FillOptionsFromEnvVariables(BootstrapperOptions options, IDictionary envVariables)
{
var latestVersion = envVariables.GetKey(EnvArgs.PaketVersionEnv);
var latestVersion = envVariables.GetKey(EnvArgs.PaketVersionEnvPosix) ?? envVariables.GetKey(EnvArgs.PaketVersionEnv) ;
if (latestVersion != null)
{
options.DownloadArguments.LatestVersion = latestVersion;
Expand Down
29 changes: 29 additions & 0 deletions tests/Paket.Bootstrapper.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,35 @@ public void LatestVersion_FromEnvironmentVariable()
Assert.That(result.DownloadArguments.LatestVersion, Is.EqualTo("1.0"));
}

[Test]
public void LatestVersion_FromEnvironmentVariablePosix()
{
//arrange
var envVariables= new Dictionary<string, string>();
envVariables.Add(ArgumentParser.EnvArgs.PaketVersionEnvPosix, "1.0");

//act
var result = Parse(new string[] {}, null, envVariables);

//assert
Assert.That(result.DownloadArguments.LatestVersion, Is.EqualTo("1.0"));
}

[Test]
public void LatestVersion_Set_Both_FromEnvironmentVariable_Posix_Wins()
{
//arrange
var envVariables= new Dictionary<string, string>();
envVariables.Add(ArgumentParser.EnvArgs.PaketVersionEnv, "1.0");
envVariables.Add(ArgumentParser.EnvArgs.PaketVersionEnvPosix, "2.0");

//act
var result = Parse(new string[] {}, null, envVariables);

//assert
Assert.That(result.DownloadArguments.LatestVersion, Is.EqualTo("2.0"));
}

[Test]
public void LeftoverCommandArgs()
{
Expand Down

0 comments on commit 7c5e3eb

Please sign in to comment.