|
1 | 1 | import 'dart:convert'; |
2 | 2 | import 'dart:io'; |
3 | 3 |
|
4 | | -void main() { |
5 | | - final file = File('pana_report.json'); |
6 | | - if (!file.existsSync()) { |
| 4 | +void main(List<String> args) { |
| 5 | + final reportFile = File('pana_report.json'); |
| 6 | + if (!reportFile.existsSync()) { |
7 | 7 | print('Error: pana_report.json not found.'); |
8 | 8 | exit(1); |
9 | 9 | } |
10 | 10 |
|
11 | | - final jsonString = file.readAsStringSync(); |
12 | | - final Map<String, dynamic> report = jsonDecode(jsonString); |
| 11 | + final report = jsonDecode(reportFile.readAsStringSync()); |
| 12 | + final scores = report['scores']; |
| 13 | + final grantedPoints = scores['grantedPoints'] as int; |
| 14 | + final maxPoints = scores['maxPoints'] as int; |
13 | 15 |
|
14 | | - final scores = report['scores'] as Map<String, dynamic>?; |
15 | | - if (scores == null) { |
16 | | - print('Error: Could not find scores in pana report.'); |
17 | | - exit(1); |
18 | | - } |
19 | | - |
20 | | - final grantedPoints = scores['grantedPoints'] as int?; |
21 | | - final maxPoints = scores['maxPoints'] as int?; |
22 | | - |
23 | | - if (grantedPoints == null) { |
24 | | - print('Error: Could not find grantedPoints in pana report.'); |
25 | | - exit(1); |
| 16 | + // Default threshold is 140, but can be overridden by argument |
| 17 | + int threshold = 140; |
| 18 | + if (args.isNotEmpty) { |
| 19 | + threshold = int.tryParse(args[0]) ?? 140; |
26 | 20 | } |
27 | 21 |
|
28 | | - print('Pana Score: $grantedPoints / ${maxPoints ?? "Unknown"}'); |
| 22 | + print('Pana Score: $grantedPoints / $maxPoints'); |
29 | 23 |
|
30 | | - if (grantedPoints < 160) { |
31 | | - print( |
32 | | - 'Failure: Pana score $grantedPoints is below the required threshold of 160.', |
33 | | - ); |
| 24 | + if (grantedPoints < threshold) { |
| 25 | + print('Error: Score is below the threshold of $threshold.'); |
34 | 26 | exit(1); |
35 | 27 | } |
36 | 28 |
|
37 | | - print('Success: Pana score meets the requirement.'); |
| 29 | + print('Success: Score meets the threshold.'); |
38 | 30 | } |
0 commit comments