Showing
2 changed files
with
26 additions
and
6 deletions
@@ -17,12 +17,14 @@ | @@ -17,12 +17,14 @@ | ||
17 | import 'dart:convert'; | 17 | import 'dart:convert'; |
18 | import 'dart:io'; | 18 | import 'dart:io'; |
19 | 19 | ||
20 | +import 'package:args/args.dart'; | ||
21 | + | ||
20 | String _capitalize(String s) { | 22 | String _capitalize(String s) { |
21 | if (s.isEmpty) return s; | 23 | if (s.isEmpty) return s; |
22 | return '${s[0].toUpperCase()}${s.substring(1)}'; | 24 | return '${s[0].toUpperCase()}${s.substring(1)}'; |
23 | } | 25 | } |
24 | 26 | ||
25 | -String _uncapitalize(String s) { | 27 | +String _uncapitalized(String s) { |
26 | if (s.isEmpty) return s; | 28 | if (s.isEmpty) return s; |
27 | return '${s[0].toLowerCase()}${s.substring(1)}'; | 29 | return '${s[0].toLowerCase()}${s.substring(1)}'; |
28 | } | 30 | } |
@@ -43,7 +45,7 @@ class FontDesc { | @@ -43,7 +45,7 @@ class FontDesc { | ||
43 | final String name; | 45 | final String name; |
44 | 46 | ||
45 | String get dartFamily => | 47 | String get dartFamily => |
46 | - _uncapitalize(family == null ? key : family!.replaceAll(' ', '')); | 48 | + _uncapitalized(family == null ? key : family!.replaceAll(' ', '')); |
47 | 49 | ||
48 | String get fontDartName => dartFamily + (sub ?? ''); | 50 | String get fontDartName => dartFamily + (sub ?? ''); |
49 | 51 | ||
@@ -52,7 +54,7 @@ class FontDesc { | @@ -52,7 +54,7 @@ class FontDesc { | ||
52 | 54 | ||
53 | Iterable<FontDesc> getFonts(Map m) sync* { | 55 | Iterable<FontDesc> getFonts(Map m) sync* { |
54 | for (final f in m['items']) { | 56 | for (final f in m['items']) { |
55 | - final family = _uncapitalize(f['family'].replaceAll(' ', '')); | 57 | + final family = _uncapitalized(f['family'].replaceAll(' ', '')); |
56 | 58 | ||
57 | for (final s in f['files'].entries) { | 59 | for (final s in f['files'].entries) { |
58 | var sub = _capitalize(s.key); | 60 | var sub = _capitalize(s.key); |
@@ -103,13 +105,30 @@ Iterable<FontDesc> getFonts(Map m) sync* { | @@ -103,13 +105,30 @@ Iterable<FontDesc> getFonts(Map m) sync* { | ||
103 | } | 105 | } |
104 | 106 | ||
105 | void main(List<String> args) async { | 107 | void main(List<String> args) async { |
108 | + final parser = ArgParser(); | ||
109 | + parser.addOption( | ||
110 | + 'key', | ||
111 | + abbr: 'k', | ||
112 | + mandatory: true, | ||
113 | + help: | ||
114 | + 'Google API key, can be generated here: https://console.cloud.google.com/apis/credentials', | ||
115 | + ); | ||
116 | + final ArgResults results; | ||
117 | + try { | ||
118 | + results = parser.parse(args); | ||
119 | + } catch (e) { | ||
120 | + print(parser.usage); | ||
121 | + print(e); | ||
122 | + return; | ||
123 | + } | ||
124 | + | ||
106 | final f = File('fonts.json'); | 125 | final f = File('fonts.json'); |
107 | final d = StringBuffer(); | 126 | final d = StringBuffer(); |
108 | 127 | ||
109 | if (f.existsSync()) { | 128 | if (f.existsSync()) { |
110 | d.write(await f.readAsString()); | 129 | d.write(await f.readAsString()); |
111 | } else { | 130 | } else { |
112 | - final key = args[0]; | 131 | + final key = results['key']; |
113 | final http = HttpClient(); | 132 | final http = HttpClient(); |
114 | print('Downloading...'); | 133 | print('Downloading...'); |
115 | final q = await http.getUrl(Uri.parse( | 134 | final q = await http.getUrl(Uri.parse( |
@@ -6,10 +6,11 @@ issue_tracker: https://github.com/DavBfr/dart_pdf/issues | @@ -6,10 +6,11 @@ issue_tracker: https://github.com/DavBfr/dart_pdf/issues | ||
6 | version: 1.0.0 | 6 | version: 1.0.0 |
7 | 7 | ||
8 | environment: | 8 | environment: |
9 | - sdk: ">=2.12.0 <3.0.0" | ||
10 | - flutter: ">=1.16.0" | 9 | + sdk: ">=2.18.0 <3.0.0" |
10 | + flutter: ">=3.7.0" | ||
11 | 11 | ||
12 | dependencies: | 12 | dependencies: |
13 | + args: | ||
13 | flutter: | 14 | flutter: |
14 | sdk: flutter | 15 | sdk: flutter |
15 | markdown: | 16 | markdown: |
-
Please register or login to post a comment