File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed
Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments