Skip to content

Commit 82f4f95

Browse files
committed
Add ability to replace existing entries in cli
1 parent e31f9be commit 82f4f95

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/EasySign.CommandLine/BundleWorker.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public abstract partial class CommandProvider<T>
2525
/// Runs the add command.
2626
/// </summary>
2727
/// <param name="statusContext">The status context for interacting with <see cref="AnsiConsole.Status"/>.</param>
28-
protected virtual void RunAdd(StatusContext statusContext)
28+
/// <param name="replace">A value indicating whether to replace existing entries.</param>
29+
protected virtual void RunAdd(StatusContext statusContext, bool replace)
2930
{
3031
if (Bundle == null)
3132
{
@@ -40,15 +41,23 @@ protected virtual void RunAdd(StatusContext statusContext)
4041

4142
statusContext.Status("[yellow]Adding Files[/]");
4243

43-
Parallel.ForEach(Utilities.SafeEnumerateFiles(Bundle.RootPath, "*"), file =>
44+
_ = Parallel.ForEach(Utilities.SafeEnumerateFiles(Bundle.RootPath, "*"), file =>
4445
{
4546
if (file == Bundle.BundlePath) return;
4647

4748
var entryName = Manifest.GetNormalizedEntryName(Path.GetRelativePath(Bundle.RootPath, file));
4849

4950
if (Bundle.Manifest.Entries.ContainsKey(entryName))
5051
{
51-
AnsiConsole.MarkupLine($"[{Color.Orange1}]Exists:[/] {entryName}");
52+
if (!replace)
53+
{
54+
AnsiConsole.MarkupLine($"[{Color.Orange1}]Exists:[/] {entryName}");
55+
return;
56+
}
57+
58+
Bundle.DeleteEntry(entryName);
59+
Bundle.AddEntry(file);
60+
AnsiConsole.MarkupLine($"[{Color.Cyan2}]Replaced:[/] {entryName}");
5261
}
5362
else
5463
{

src/EasySign.CommandLine/CommandProvider.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ public Command Add
3333
{
3434
get
3535
{
36+
var replaceOpt = new Option<bool>("--replace", "Replace existing entries");
37+
replaceOpt.AddAlias("-r");
38+
3639
var command = new Command("add", "Create new bundle or update an existing one")
3740
{
3841
BundlePath,
42+
replaceOpt,
3943
};
4044

41-
command.SetHandler((bundlePath) =>
45+
command.SetHandler((bundlePath, replace) =>
4246
{
4347
InitializeBundle(bundlePath);
44-
Utilities.RunInStatusContext("[yellow]Preparing[/]", ctx => RunAdd(ctx));
45-
}, BundlePath);
48+
Utilities.RunInStatusContext("[yellow]Preparing[/]", ctx => RunAdd(ctx, replace));
49+
}, BundlePath, replaceOpt);
4650

4751
return command;
4852
}

0 commit comments

Comments
 (0)