@@ -25,8 +25,8 @@ class Program
25
25
private CommandOption _csvOption ;
26
26
private CommandOption _destinationOption ;
27
27
private CommandOption _whatIf ;
28
- private CommandOption _warningsOnly ;
29
- private CommandOption _warningsAsErrors ;
28
+ private CommandOption _quiet ;
29
+ private CommandOption _ignoreErrors ;
30
30
31
31
public ILogger Logger
32
32
{
@@ -47,16 +47,16 @@ public Program(
47
47
CommandOption csvOption ,
48
48
CommandOption destinationOption ,
49
49
CommandOption whatIfOption ,
50
- CommandOption warningsOnly ,
51
- CommandOption warningsAsErrors )
50
+ CommandOption quiet ,
51
+ CommandOption ignoreErrors )
52
52
{
53
53
_app = app ;
54
54
_sourceOption = sourceOption ;
55
55
_csvOption = csvOption ;
56
56
_destinationOption = destinationOption ;
57
57
_whatIf = whatIfOption ;
58
- _warningsOnly = warningsOnly ;
59
- _warningsAsErrors = warningsAsErrors ;
58
+ _quiet = quiet ;
59
+ _ignoreErrors = ignoreErrors ;
60
60
}
61
61
62
62
static int Main ( string [ ] args )
@@ -86,14 +86,14 @@ static int Main(string[] args)
86
86
"Performs a dry run of the command with the given arguments without copying the packages" ,
87
87
CommandOptionType . NoValue ) ;
88
88
89
- var warningsOnly = app . Option (
89
+ var quiet = app . Option (
90
90
"--quiet" ,
91
91
"Avoids printing to the output anything other than warnings or errors" ,
92
92
CommandOptionType . NoValue ) ;
93
93
94
- var warningsAsErrors = app . Option (
95
- "--warningsaserrors " ,
96
- "Treats warnigns and errors and stops the execution of the command " ,
94
+ var ignoreErrors = app . Option (
95
+ "--ignore-errors " ,
96
+ "Treats errors as warnings and allows the command to continue executing " ,
97
97
CommandOptionType . NoValue ) ;
98
98
99
99
var program = new Program (
@@ -102,8 +102,8 @@ static int Main(string[] args)
102
102
csvOption ,
103
103
destinationOption ,
104
104
whatIfOption ,
105
- warningsOnly ,
106
- warningsAsErrors ) ;
105
+ quiet ,
106
+ ignoreErrors ) ;
107
107
108
108
app . OnExecute ( new Func < int > ( program . Execute ) ) ;
109
109
@@ -128,7 +128,17 @@ private int Execute()
128
128
129
129
EnsureNoExtraSourcePackagesFound ( packagesFromSource , expandedPackages ) ;
130
130
131
- EmitWarningsForMissingPackages ( packagesFromSource , packagesFromCsv ) ;
131
+ var errors = new List < string > ( ) ;
132
+ EmitWarningsForMissingPackages ( packagesFromSource , packagesFromCsv , errors ) ;
133
+
134
+ if ( errors . Count > 0 )
135
+ {
136
+ WriteErrorMessage ( errors ) ;
137
+ if ( ! _ignoreErrors . HasValue ( ) )
138
+ {
139
+ return Error ;
140
+ }
141
+ }
132
142
133
143
EnsureDestinationDirectories (
134
144
arguments . DestinationFolder ,
@@ -150,6 +160,24 @@ private int Execute()
150
160
}
151
161
}
152
162
163
+ private void WriteErrorMessage ( List < string > errors )
164
+ {
165
+ var header = new [ ] {
166
+ "The list of packages in the source folder is inconsistent with the list of packages in the CSV file:"
167
+ } ;
168
+
169
+ var message = string . Join ( $ "{ Environment . NewLine } ", header . Concat ( errors ) ) ;
170
+
171
+ if ( _ignoreErrors . HasValue ( ) )
172
+ {
173
+ Logger . LogWarning ( message ) ;
174
+ }
175
+ else
176
+ {
177
+ Logger . LogError ( message ) ;
178
+ }
179
+ }
180
+
153
181
private void CreateProjectJsonFiles ( IEnumerable < PackageItem > packages )
154
182
{
155
183
var packagesByFolder = packages . GroupBy ( p => Path . GetDirectoryName ( p . DestinationPath ) ) ;
@@ -161,7 +189,7 @@ private void CreateProjectJsonFiles(IEnumerable<PackageItem> packages)
161
189
var jsonFileBuilder = new ProjectJsonFileBuilder (
162
190
Path . Combine ( path . Key , "project.json" ) ,
163
191
_whatIf . HasValue ( ) ,
164
- _warningsAsErrors . HasValue ( ) ,
192
+ _ignoreErrors . HasValue ( ) ,
165
193
Logger ) ;
166
194
167
195
jsonFileBuilder . AddDependencies ( dependenciesList ) ;
@@ -173,7 +201,7 @@ private void CreateProjectJsonFiles(IEnumerable<PackageItem> packages)
173
201
private ILogger CreateLogger ( )
174
202
{
175
203
var loggerFactory = new LoggerFactory ( ) ;
176
- var logLevel = _warningsOnly . HasValue ( ) ? LogLevel . Warning : LogLevel . Information ;
204
+ var logLevel = _quiet . HasValue ( ) ? LogLevel . Warning : LogLevel . Information ;
177
205
178
206
loggerFactory . AddConsole ( logLevel , includeScopes : false ) ;
179
207
@@ -385,15 +413,15 @@ private void EnsureNoExtraSourcePackagesFound(IList<PackageItem> source, IList<P
385
413
}
386
414
}
387
415
388
- private void EmitWarningsForMissingPackages ( IList < PackageItem > source , IList < PackageItem > csv )
416
+ private void EmitWarningsForMissingPackages ( IList < PackageItem > source , IList < PackageItem > csv , IList < string > errors )
389
417
{
390
418
for ( int i = 0 ; i < source . Count ; i ++ )
391
419
{
392
420
if ( ! source [ i ] . FoundInCsv )
393
421
{
394
422
var msg = $@ "No entry in the csv file matched the following package:
395
423
{ source [ i ] . Name } " ;
396
- LogWarning ( msg ) ;
424
+ LogWarning ( msg , errors ) ;
397
425
}
398
426
}
399
427
@@ -403,7 +431,7 @@ private void EmitWarningsForMissingPackages(IList<PackageItem> source, IList<Pac
403
431
{
404
432
var msg = $@ "No package found in the source folder for the following csv entry:
405
433
{ csv [ i ] . Name } " ;
406
- LogWarning ( msg ) ;
434
+ LogWarning ( msg , errors ) ;
407
435
}
408
436
}
409
437
}
@@ -465,14 +493,14 @@ private void CopyPackages(IList<PackageItem> expandedPackages)
465
493
}
466
494
}
467
495
468
- private void LogWarning ( string message )
496
+ private void LogWarning ( string message , IList < string > errors )
469
497
{
470
- if ( _warningsAsErrors . HasValue ( ) )
498
+ if ( _ignoreErrors . HasValue ( ) )
471
499
{
472
- throw new InvalidOperationException ( message ) ;
500
+ Logger . LogWarning ( message ) ;
473
501
}
474
502
475
- Logger . LogWarning ( message ) ;
503
+ errors . Add ( message ) ;
476
504
}
477
505
478
506
private class PackageItem : IEquatable < PackageItem >
@@ -513,18 +541,18 @@ private class ProjectJsonFileBuilder
513
541
{
514
542
private readonly string _path ;
515
543
private readonly bool _whatIf ;
516
- private readonly bool _warningsAsErrors ;
544
+ private readonly bool _ignoreErrors ;
517
545
private readonly ILogger _logger ;
518
546
519
547
public ProjectJsonFileBuilder (
520
548
string path ,
521
549
bool whatIf ,
522
- bool warningsAsErrors ,
550
+ bool ignoreErrors ,
523
551
ILogger logger )
524
552
{
525
553
_path = path ;
526
554
_whatIf = whatIf ;
527
- _warningsAsErrors = warningsAsErrors ;
555
+ _ignoreErrors = ignoreErrors ;
528
556
_logger = logger ;
529
557
}
530
558
@@ -580,7 +608,7 @@ private IDictionary<string, string> CreateDependenciesDictionary()
580
608
if ( dictionary . ContainsKey ( dependency . Identity ) )
581
609
{
582
610
var message = $ "A duplicate dependency exists in { _path } , name = { dependency . Identity } ";
583
- if ( _warningsAsErrors )
611
+ if ( _ignoreErrors )
584
612
{
585
613
throw new InvalidOperationException ( message ) ;
586
614
}
0 commit comments