Skip to content

Commit 812a46e

Browse files
Merge pull request #732 from jimmylewis/cli-whatif
Add a --whatif option to CLI update command
2 parents 2f667c8 + f80928d commit 812a46e

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/libman/Commands/UpdateCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public UpdateCommand(IHostEnvironment environment, bool throwOnUnexpectedArg = t
4848
/// <remarks>Needs the full library id.</remarks>
4949
public CommandOption ToVersion { get; private set; }
5050

51+
/// <summary>
52+
/// Option to specify if this should print the operation that would be carried out, but not make changes.
53+
/// </summary>
54+
public CommandOption WhatIf { get; private set; }
55+
5156
public override BaseCommand Configure(CommandLineApplication parent = null)
5257
{
5358
base.Configure(parent);
@@ -56,6 +61,7 @@ public override BaseCommand Configure(CommandLineApplication parent = null)
5661
Provider = Option("--provider|-p", Resources.Text.UpdateCommandProviderOptionDesc, CommandOptionType.SingleValue);
5762
PreRelease = Option("--pre", Resources.Text.UpdateCommandPreReleaseOptionDesc, CommandOptionType.NoValue);
5863
ToVersion = Option("--to", Resources.Text.UpdateCommandToVersionOptionDesc, CommandOptionType.SingleValue);
64+
WhatIf = Option("--whatif", Resources.Text.WhatIfOptionDesc, CommandOptionType.NoValue);
5965

6066
// Reserve this.
6167
Provider.ShowInHelpText = false;
@@ -106,6 +112,12 @@ protected override async Task<int> ExecuteInternalAsync()
106112
return 0;
107113
}
108114

115+
if (WhatIf.HasValue())
116+
{
117+
Logger.Log(string.Format(Resources.Text.WhatIfOutputMessage, libraryToUpdate.Name, newVersion), LogLevel.Operation);
118+
return 0;
119+
}
120+
109121
Manifest backup = manifest.Clone();
110122
string oldLibraryName = libraryToUpdate.Name;
111123
Manifest.UpdateLibraryVersion(libraryToUpdate, newVersion);

src/libman/Resources/Text.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libman/Resources/Text.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,10 @@ Please specify a different destination.</value>
431431
<data name="UseDefault" xml:space="preserve">
432432
<value>Use the default settings for the libman.json file</value>
433433
</data>
434+
<data name="WhatIfOptionDesc" xml:space="preserve">
435+
<value>Print what operations would be carried out, without making any changes.</value>
436+
</data>
437+
<data name="WhatIfOutputMessage" xml:space="preserve">
438+
<value>Library "{0}" would be updated to latest version "{1}"</value>
439+
</data>
434440
</root>

0 commit comments

Comments
 (0)