@@ -37,7 +37,28 @@ public DumpCommand(ILogger logger, SpectreConsoleService console, DirectoryLoade
3737 _logger = logger ;
3838 _fs = fs ;
3939 }
40+ private async Task < ReturnCode > SpectreConsoleDelegate ( IFileSystem fs , string outputFile , IEnumerable < string > lines , CancellationToken ct )
41+ {
42+ foreach ( var line in lines )
43+ {
44+ _console . WriteLine ( line ) ;
45+ }
46+ return await Task . FromResult ( ReturnCode . Success ) ;
47+ }
4048
49+ private async Task < ReturnCode > WriteFileDelegate ( IFileSystem fs , string outputFile , IEnumerable < string > lines , CancellationToken ct )
50+ {
51+ try
52+ {
53+ await fs . File . WriteAllLinesAsync ( outputFile , lines , ct ) ;
54+ }
55+ catch ( Exception e )
56+ {
57+ return ReturnCode . GeneralError ;
58+ }
59+
60+ return ReturnCode . Success ;
61+ }
4162 public override async Task < int > ExecuteAsync ( CommandContext context , DumpCommandSettings settings , CancellationToken cancellationToken )
4263 {
4364 var audioExtensions = DirectoryLoaderService . ComposeAudioExtensions ( settings . IncludeExtensions ) ;
@@ -47,14 +68,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, DumpCommand
4768 . ToArray ( ) ;
4869 var returnCode = ReturnCode . Success ;
4970
50- var outputDelegate = async Task < ReturnCode > ( IFileSystem fs , string outputFile , IEnumerable < string > lines , CancellationToken ct ) =>
51- {
52- foreach ( var line in lines )
53- {
54- _console . WriteLine ( line ) ;
55- }
56- return await Task . FromResult ( ReturnCode . Success ) ;
57- } ;
71+ var outputDelegate = SpectreConsoleDelegate ;
5872 var outputSuffix = "" ;
5973
6074
@@ -66,19 +80,8 @@ public override async Task<int> ExecuteAsync(CommandContext context, DumpCommand
6680 }
6781
6882 // outputDelegate = async lines => ;
69- outputDelegate = async Task < ReturnCode > ( fs , outputFile , lines , ct ) =>
70- {
71- try
72- {
73- await fs . File . WriteAllLinesAsync ( outputFile , lines , ct ) ;
74- }
75- catch ( Exception e )
76- {
77- return ReturnCode . GeneralError ;
78- }
79-
80- return ReturnCode . Success ;
81- } ;
83+ outputDelegate = WriteFileDelegate ;
84+
8285 outputSuffix = settings . Format switch
8386 {
8487 SerializerFormat . Json => ToneJsonTagger . DefaultFileSuffix ,
0 commit comments