Skip to content

Commit 35d7d10

Browse files
authored
Merge pull request #116 from pascalberger/feature/version-settings-aliases
(GH-115) Add overloads for NpmVersion which accept a settings object
2 parents af4da1b + 9c1d323 commit 35d7d10

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

src/Cake.Npm/NpmVersionAliases.cs

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,73 @@ public static string NpmVersion(this ICakeContext context)
3333
}
3434

3535
AddinInformation.LogVersionInformation(context.Log);
36-
var settings = new NpmVersionSettings
36+
return context.NpmVersion(new NpmVersionSettings());
37+
}
38+
39+
/// <summary>
40+
/// Versions all packages for the project in the current working directory
41+
/// using the settings returned by a configurator.
42+
/// </summary>
43+
/// <param name="context">The context.</param>
44+
/// <param name="configurator">The settings configurator.</param>
45+
/// <example>
46+
/// <code>
47+
/// <![CDATA[
48+
/// var versionString = NpmVersion(settings => settings.WithLogLevel(NpmLogLevel.Verbose));
49+
/// ]]>
50+
/// </code>
51+
/// </example>
52+
[CakeMethodAlias]
53+
[CakeAliasCategory("Version")]
54+
public static string NpmVersion(this ICakeContext context, Action<NpmVersionSettings> configurator)
55+
{
56+
if (context == null)
57+
{
58+
throw new ArgumentNullException(nameof(context));
59+
}
60+
61+
if (configurator == null)
62+
{
63+
throw new ArgumentNullException(nameof(configurator));
64+
}
65+
66+
var settings = new NpmVersionSettings();
67+
configurator(settings);
68+
return context.NpmVersion(settings);
69+
}
70+
71+
/// <summary>
72+
/// Versions all packages for the project in the current working directory
73+
/// using the specified settings.
74+
/// </summary>
75+
/// <param name="context">The context.</param>
76+
/// <param name="settings">The settings.</param>
77+
/// <example>
78+
/// <code>
79+
/// <![CDATA[
80+
/// var settings = new NpmVersionSettings();
81+
/// settings.WithLogLevel(NpmLogLevel.Verbose);
82+
/// var versionString = NpmVersion(settings);
83+
/// ]]>
84+
/// </code>
85+
/// </example>
86+
[CakeMethodAlias]
87+
[CakeAliasCategory("Version")]
88+
public static string NpmVersion(this ICakeContext context, NpmVersionSettings settings)
89+
{
90+
if (context == null)
3791
{
38-
RedirectStandardOutput = true
39-
};
40-
return new NpmVersionTool(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log).Version(settings);
92+
throw new ArgumentNullException(nameof(context));
93+
}
94+
95+
if (settings == null)
96+
{
97+
throw new ArgumentNullException(nameof(settings));
98+
}
99+
100+
AddinInformation.LogVersionInformation(context.Log);
101+
var tool = new NpmVersionTool(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log);
102+
return tool.Version(settings);
41103
}
42104
}
43105
}

src/Cake.Npm/Version/NpmVersionSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class NpmVersionSettings : NpmSettings
1414
public NpmVersionSettings()
1515
: base("version")
1616
{
17+
// Since 'NpmVersion' returns a string we should redirect standard output.
18+
RedirectStandardOutput = true;
1719
}
1820
}
1921
}

0 commit comments

Comments
 (0)