-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdart_cli_with_fpdart.dart
53 lines (43 loc) · 1.68 KB
/
dart_cli_with_fpdart.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'dart:io';
import 'package:args/args.dart';
import 'package:dart_cli_with_fpdart/arguments_parser.dart';
import 'package:dart_cli_with_fpdart/cli_error.dart';
import 'package:dart_cli_with_fpdart/config_reader.dart';
import 'package:dart_cli_with_fpdart/file_reader.dart';
import 'package:dart_cli_with_fpdart/main.dart';
import 'package:dart_cli_with_fpdart/main_layer.dart';
import 'package:dart_cli_with_fpdart/yaml_loader.dart';
void main(List<String> arguments) async =>
program(arguments).match<void>((cliError) {
exitCode = 2;
final errorMessage = switch (cliError) {
InvalidArgumentsError() => "Invalid CLI arguments",
LoadYamlOptionsError(yamlLoaderError: final yamlLoaderError) =>
"Error while loading yaml configuration: $yamlLoaderError",
MissingPackageNameError(path: final path) =>
"Missing package name in pubspec.yaml at path '$path'",
ReadFilesError() => "Error while reading project files",
ReadFileImportsError() => "Error while decoding file imports",
};
stderr.writeln(errorMessage);
}, (result) {
exitCode = 0;
stdout.writeln();
stdout.writeln("Entry 👉: ${result.entry}");
stdout.writeln();
stdout.writeln("Unused 👎");
for (final file in result.unused) {
stdout.writeln(" => $file");
}
stdout.writeln();
stdout.writeln("Used 👍");
for (final file in result.used) {
stdout.writeln(" => $file");
}
}).run(
AppMainLayer(
argumentsParser: ArgumentsParserImpl(ArgParser()),
configReader: ConfigReaderImpl(YamlLoaderImpl()),
fileReader: FileReaderImpl(),
),
);