Skip to content

Commit

Permalink
Merge pull request #27 from joshstrohminger/install-any-arg
Browse files Browse the repository at this point in the history
Allow any argument to be added to an install command
  • Loading branch information
MilovanovM authored Jan 23, 2019
2 parents e10534b + a79c9b3 commit 663192f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Cake.Yarn.Tests/YarnInstallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public void Install_Settings_OfflineInstall_Should_Use_Correct_Argument_Provided
result.Args.ShouldBe("install --offline");
}

[Fact]
public void Install_Settings_WithArgument_Should_Use_Arguments_Provided_In_YarnInstallSettings()
{
_fixture.InstallSettings = s => s.WithArgument("--verbose").WithArgument("--force");

var result = _fixture.Run();

result.Args.ShouldBe("install --verbose --force");
}

[Fact]
public void Several_Install_Settings_Should_Use_Correct_Argument_Provided_In_YarnInstallSettings()
{
Expand Down
23 changes: 23 additions & 0 deletions src/Cake.Yarn/YarnInstallSettings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Cake.Core;
using Cake.Core.IO;

Expand All @@ -9,6 +11,7 @@ namespace Cake.Yarn
public class YarnInstallSettings : YarnRunnerSettings
{
private bool _explicitProductionFlag;
private readonly IList<string> _arguments = new List<string>();

/// <summary>
/// Yarn "install" settings
Expand Down Expand Up @@ -53,6 +56,11 @@ protected override void EvaluateCore(ProcessArgumentBuilder args)
{
args.Append("--offline");
}

foreach (var arg in _arguments)
{
args.Append(arg);
}
}

/// <summary>
Expand Down Expand Up @@ -116,6 +124,16 @@ public YarnInstallSettings Offline(bool enabled = true)
return this;
}

/// <summary>
/// Apply any individual argument.
/// </summary>
/// <param name="arg">The individual argument to use.</param>
public YarnInstallSettings WithArgument(string arg)
{
_arguments.Add(arg);
return this;
}

/// <summary>
/// --production
/// </summary>
Expand Down Expand Up @@ -145,5 +163,10 @@ public YarnInstallSettings Offline(bool enabled = true)
/// --offline
/// </summary>
public bool OfflineInstall { get; internal set; }

/// <summary>
/// Arguments to pass to the target script
/// </summary>
public IReadOnlyCollection<string> Arguments => new ReadOnlyCollection<string>(_arguments);
}
}

0 comments on commit 663192f

Please sign in to comment.