-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.dart
93 lines (74 loc) · 2.06 KB
/
cli.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
library cli;
import 'dart:io' show File, exit;
import 'package:args/args.dart' show ArgParser, ArgResults;
import 'package:emojiscraper/emojiscraper.dart' as scraper;
import 'package:interact/interact.dart' show Select, Spinner, SpinnerState;
// generated by `dart run build_runner`
import './app_info.dart' as app_info;
part './options.dart';
part './commands.dart';
Future<void> run({required List<String> args}) async {
try {
final app = _generate(ArgParser());
final cli = app.parse(args);
if (_validFlagsOrOptionsPassed(cli) == false) {
_printNoArgsHelp();
}
// show help
if (cli['help']) {
_help(app.usage);
}
// show version
if (cli['version']) {
_version();
}
// list versions
if (cli['list']) {
await _printAvailableVersions();
}
var edition = cli['edition'];
final format = cli['format'],
writeTo = cli['writeTo'],
interactive = cli['interactive'];
edition ??= await _getEdition(interactive);
final downloadSpinner = _spinner('Downloading ...');
final data = await scraper.fetchEmojiData(edition);
downloadSpinner.done();
switch (writeTo) {
case "path":
String? emoji;
File? file;
switch (format) {
case "json":
file = await File('$edition-emoji-sequences.json').create();
emoji = scraper.parseTextToJson(data);
break;
case "raw":
file = await File('$edition-emoji-sequences.txt').create();
emoji = data;
break;
default:
_invalidState();
}
await file.writeAsString(emoji, flush: true);
break;
case "stdout":
switch (format) {
case "json":
final json = scraper.parseTextToJson(data);
print(json);
break;
case "raw":
print(data);
break;
default:
_invalidState();
}
break;
default:
_invalidState();
}
} catch (e) {
_printAllErrors(e);
}
}