Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding PAKET_VERSION posix compliant environment variable for bootstrapper #2857

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 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,11 @@ 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 all [settings listed above](#In-application-settings) with two exceptions:
1. `paket.bootstrapper.exe.config` becomes `paket.exe.config`
2. you can no longer use the command line to specify


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