Skip to content

Commit fbdfaf6

Browse files
authored
Fix build, update deps, clean up CLI samples (#223)
1 parent e6d6bab commit fbdfaf6

File tree

29 files changed

+136
-163
lines changed

29 files changed

+136
-163
lines changed

.github/workflows/dart.yml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Created with package:mono_repo v6.6.1
1+
# Created with package:mono_repo v6.6.2
22
name: Dart CI
33
on:
44
push:
@@ -33,20 +33,20 @@ jobs:
3333
name: Checkout repository
3434
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
3535
- name: mono_repo self validate
36-
run: dart pub global activate mono_repo 6.6.1
36+
run: dart pub global activate mono_repo 6.6.2
3737
- name: mono_repo self validate
3838
run: dart pub global run mono_repo generate --validate
3939
job_002:
40-
name: "analysis; Dart dev; PKGS: command_line, enhanced_enums, extension_methods, ffi/hello_world, ffi/primitives, ffi/structs, ffi/system-command, ffi/test_utils, isolates, native_app, null_safety/calculate_lix, package_constraint_solver, parameters, server/google_apis, server/simple; `dart analyze --fatal-infos .`"
40+
name: "analysis; Dart dev; PKGS: command_line, enhanced_enums, extension_methods, ffi/hello_world, ffi/primitives, ffi/structs, ffi/system_command, ffi/test_utils, isolates, native_app, null_safety/calculate_lix, package_constraint_solver, parameters, server/google_apis, server/simple; `dart analyze --fatal-infos .`"
4141
runs-on: ubuntu-latest
4242
steps:
4343
- name: Cache Pub hosted dependencies
4444
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
4545
with:
4646
path: "~/.pub-cache/hosted"
47-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system-command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-package_constraint_solver-parameters-server/google_apis-server/simple;commands:analyze"
47+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system_command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-package_constraint_solver-parameters-server/google_apis-server/simple;commands:analyze"
4848
restore-keys: |
49-
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system-command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-package_constraint_solver-parameters-server/google_apis-server/simple
49+
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system_command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-package_constraint_solver-parameters-server/google_apis-server/simple
5050
os:ubuntu-latest;pub-cache-hosted;sdk:dev
5151
os:ubuntu-latest;pub-cache-hosted
5252
os:ubuntu-latest
@@ -111,15 +111,15 @@ jobs:
111111
run: dart analyze --fatal-infos .
112112
if: "always() && steps.ffi_structs_pub_upgrade.conclusion == 'success'"
113113
working-directory: ffi/structs
114-
- id: ffi_system-command_pub_upgrade
115-
name: "ffi/system-command; dart pub upgrade"
114+
- id: ffi_system_command_pub_upgrade
115+
name: ffi/system_command; dart pub upgrade
116116
run: dart pub upgrade
117117
if: "always() && steps.checkout.conclusion == 'success'"
118-
working-directory: ffi/system-command
119-
- name: "ffi/system-command; dart analyze --fatal-infos ."
118+
working-directory: ffi/system_command
119+
- name: "ffi/system_command; dart analyze --fatal-infos ."
120120
run: dart analyze --fatal-infos .
121-
if: "always() && steps.ffi_system-command_pub_upgrade.conclusion == 'success'"
122-
working-directory: ffi/system-command
121+
if: "always() && steps.ffi_system_command_pub_upgrade.conclusion == 'success'"
122+
working-directory: ffi/system_command
123123
- id: ffi_test_utils_pub_upgrade
124124
name: ffi/test_utils; dart pub upgrade
125125
run: dart pub upgrade
@@ -195,16 +195,16 @@ jobs:
195195
needs:
196196
- job_001
197197
job_003:
198-
name: "analysis; Dart dev; PKGS: command_line, enhanced_enums, extension_methods, ffi/hello_world, ffi/primitives, ffi/structs, ffi/system-command, ffi/test_utils, isolates, native_app, null_safety/calculate_lix, package_constraint_solver, parameters, server/google_apis, server/simple; `dart format --output=none --set-exit-if-changed .`"
198+
name: "analysis; Dart dev; PKGS: command_line, enhanced_enums, extension_methods, ffi/hello_world, ffi/primitives, ffi/structs, ffi/system_command, ffi/test_utils, isolates, native_app, null_safety/calculate_lix, package_constraint_solver, parameters, server/google_apis, server/simple; `dart format --output=none --set-exit-if-changed .`"
199199
runs-on: ubuntu-latest
200200
steps:
201201
- name: Cache Pub hosted dependencies
202202
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
203203
with:
204204
path: "~/.pub-cache/hosted"
205-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system-command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-package_constraint_solver-parameters-server/google_apis-server/simple;commands:format"
205+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system_command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-package_constraint_solver-parameters-server/google_apis-server/simple;commands:format"
206206
restore-keys: |
207-
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system-command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-package_constraint_solver-parameters-server/google_apis-server/simple
207+
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system_command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-package_constraint_solver-parameters-server/google_apis-server/simple
208208
os:ubuntu-latest;pub-cache-hosted;sdk:dev
209209
os:ubuntu-latest;pub-cache-hosted
210210
os:ubuntu-latest
@@ -269,15 +269,15 @@ jobs:
269269
run: "dart format --output=none --set-exit-if-changed ."
270270
if: "always() && steps.ffi_structs_pub_upgrade.conclusion == 'success'"
271271
working-directory: ffi/structs
272-
- id: ffi_system-command_pub_upgrade
273-
name: "ffi/system-command; dart pub upgrade"
272+
- id: ffi_system_command_pub_upgrade
273+
name: ffi/system_command; dart pub upgrade
274274
run: dart pub upgrade
275275
if: "always() && steps.checkout.conclusion == 'success'"
276-
working-directory: ffi/system-command
277-
- name: "ffi/system-command; dart format --output=none --set-exit-if-changed ."
276+
working-directory: ffi/system_command
277+
- name: "ffi/system_command; dart format --output=none --set-exit-if-changed ."
278278
run: "dart format --output=none --set-exit-if-changed ."
279-
if: "always() && steps.ffi_system-command_pub_upgrade.conclusion == 'success'"
280-
working-directory: ffi/system-command
279+
if: "always() && steps.ffi_system_command_pub_upgrade.conclusion == 'success'"
280+
working-directory: ffi/system_command
281281
- id: ffi_test_utils_pub_upgrade
282282
name: ffi/test_utils; dart pub upgrade
283283
run: dart pub upgrade
@@ -353,16 +353,16 @@ jobs:
353353
needs:
354354
- job_001
355355
job_004:
356-
name: "analysis; Dart stable; PKGS: command_line, enhanced_enums, extension_methods, ffi/hello_world, ffi/primitives, ffi/structs, ffi/system-command, ffi/test_utils, isolates, native_app, null_safety/calculate_lix, parameters, server/google_apis, server/simple; `dart analyze --fatal-infos .`"
356+
name: "analysis; Dart stable; PKGS: command_line, enhanced_enums, extension_methods, ffi/hello_world, ffi/primitives, ffi/structs, ffi/system_command, ffi/test_utils, isolates, native_app, null_safety/calculate_lix, parameters, server/google_apis, server/simple; `dart analyze --fatal-infos .`"
357357
runs-on: ubuntu-latest
358358
steps:
359359
- name: Cache Pub hosted dependencies
360360
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
361361
with:
362362
path: "~/.pub-cache/hosted"
363-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system-command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-parameters-server/google_apis-server/simple;commands:analyze"
363+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system_command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-parameters-server/google_apis-server/simple;commands:analyze"
364364
restore-keys: |
365-
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system-command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-parameters-server/google_apis-server/simple
365+
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system_command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-parameters-server/google_apis-server/simple
366366
os:ubuntu-latest;pub-cache-hosted;sdk:stable
367367
os:ubuntu-latest;pub-cache-hosted
368368
os:ubuntu-latest
@@ -427,15 +427,15 @@ jobs:
427427
run: dart analyze --fatal-infos .
428428
if: "always() && steps.ffi_structs_pub_upgrade.conclusion == 'success'"
429429
working-directory: ffi/structs
430-
- id: ffi_system-command_pub_upgrade
431-
name: "ffi/system-command; dart pub upgrade"
430+
- id: ffi_system_command_pub_upgrade
431+
name: ffi/system_command; dart pub upgrade
432432
run: dart pub upgrade
433433
if: "always() && steps.checkout.conclusion == 'success'"
434-
working-directory: ffi/system-command
435-
- name: "ffi/system-command; dart analyze --fatal-infos ."
434+
working-directory: ffi/system_command
435+
- name: "ffi/system_command; dart analyze --fatal-infos ."
436436
run: dart analyze --fatal-infos .
437-
if: "always() && steps.ffi_system-command_pub_upgrade.conclusion == 'success'"
438-
working-directory: ffi/system-command
437+
if: "always() && steps.ffi_system_command_pub_upgrade.conclusion == 'success'"
438+
working-directory: ffi/system_command
439439
- id: ffi_test_utils_pub_upgrade
440440
name: ffi/test_utils; dart pub upgrade
441441
run: dart pub upgrade
@@ -502,16 +502,16 @@ jobs:
502502
needs:
503503
- job_001
504504
job_005:
505-
name: "analysis; Dart stable; PKGS: command_line, enhanced_enums, extension_methods, ffi/hello_world, ffi/primitives, ffi/structs, ffi/system-command, ffi/test_utils, isolates, native_app, null_safety/calculate_lix, parameters, server/google_apis, server/simple; `dart format --output=none --set-exit-if-changed .`"
505+
name: "analysis; Dart stable; PKGS: command_line, enhanced_enums, extension_methods, ffi/hello_world, ffi/primitives, ffi/structs, ffi/system_command, ffi/test_utils, isolates, native_app, null_safety/calculate_lix, parameters, server/google_apis, server/simple; `dart format --output=none --set-exit-if-changed .`"
506506
runs-on: ubuntu-latest
507507
steps:
508508
- name: Cache Pub hosted dependencies
509509
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
510510
with:
511511
path: "~/.pub-cache/hosted"
512-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system-command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-parameters-server/google_apis-server/simple;commands:format"
512+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system_command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-parameters-server/google_apis-server/simple;commands:format"
513513
restore-keys: |
514-
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system-command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-parameters-server/google_apis-server/simple
514+
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:command_line-enhanced_enums-extension_methods-ffi/hello_world-ffi/primitives-ffi/structs-ffi/system_command-ffi/test_utils-isolates-native_app-null_safety/calculate_lix-parameters-server/google_apis-server/simple
515515
os:ubuntu-latest;pub-cache-hosted;sdk:stable
516516
os:ubuntu-latest;pub-cache-hosted
517517
os:ubuntu-latest
@@ -576,15 +576,15 @@ jobs:
576576
run: "dart format --output=none --set-exit-if-changed ."
577577
if: "always() && steps.ffi_structs_pub_upgrade.conclusion == 'success'"
578578
working-directory: ffi/structs
579-
- id: ffi_system-command_pub_upgrade
580-
name: "ffi/system-command; dart pub upgrade"
579+
- id: ffi_system_command_pub_upgrade
580+
name: ffi/system_command; dart pub upgrade
581581
run: dart pub upgrade
582582
if: "always() && steps.checkout.conclusion == 'success'"
583-
working-directory: ffi/system-command
584-
- name: "ffi/system-command; dart format --output=none --set-exit-if-changed ."
583+
working-directory: ffi/system_command
584+
- name: "ffi/system_command; dart format --output=none --set-exit-if-changed ."
585585
run: "dart format --output=none --set-exit-if-changed ."
586-
if: "always() && steps.ffi_system-command_pub_upgrade.conclusion == 'success'"
587-
working-directory: ffi/system-command
586+
if: "always() && steps.ffi_system_command_pub_upgrade.conclusion == 'success'"
587+
working-directory: ffi/system_command
588588
- id: ffi_test_utils_pub_upgrade
589589
name: ffi/test_utils; dart pub upgrade
590590
run: dart pub upgrade

command_line/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Command line app sample
2+
23
This sample demonstrates how to parse command line options into Dart objects
34
using [`package:build_cli_annotations`][build-cli], read environment variables,
45
use third-party packages like `package:github` and use core library APIs like
56
DateTime.
67

78
## Adding new CLI options
9+
810
To add new command line options to `lib/src/options.dart`, update the `Options`
911
class and re-run `build_runner`:
1012

@@ -13,6 +15,7 @@ dart run build_runner build
1315
```
1416

1517
## About this project
18+
1619
`bin/github_activity.dart` is a command line application that fetches stats for
1720
a GitHub user and prints them to the console.
1821

command_line/lib/src/formatter.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ abstract class EventFormatter {
1111
String format(Event event);
1212
}
1313

14-
/// Returns a formatted string of the form `Friday, October 18 at 13:55 PM:
15-
/// <User> opened <URL>`.
14+
/// Returns a formatted string of the form:
15+
/// `Friday, October 18 at 13:55 PM: <User> opened <URL>`.
1616
class DefaultEventFormatter implements EventFormatter {
17-
static final dateFormat = DateFormat("EEEE, MMMM d 'at' HH:mm a");
17+
static final DateFormat dateFormat = DateFormat("EEEE, MMMM d 'at' HH:mm a");
1818

1919
const DefaultEventFormatter();
2020

@@ -23,30 +23,31 @@ class DefaultEventFormatter implements EventFormatter {
2323
var date = dateFormat.format(event.createdAt!.toLocal());
2424
var type = event.type;
2525
var username = event.actor!.login;
26-
var url = util.getUrl(event);
26+
var url = util.extractUrl(event);
2727
if (url == null) {
2828
return '$date: [$type]';
2929
}
30-
var action = util.getAction(event);
30+
var action = util.extractAction(event);
3131

3232
return '$date: $username $action $url';
3333
}
3434
}
3535

3636
class MarkdownEventFormatter implements EventFormatter {
37-
static final dateFormat = DateFormat('EEE, M/d/y');
37+
static final DateFormat dateFormat = DateFormat('EEE, M/d/y');
38+
3839
@override
3940
String format(Event event) {
4041
var date = dateFormat.format(event.createdAt!.toLocal());
4142
var type = event.type;
42-
var action = util.getAction(event);
43-
var url = util.getUrl(event);
43+
var action = util.extractAction(event);
44+
var url = util.extractUrl(event);
4445
if (url == null) {
4546
return '- ($date): [$type]';
4647
}
47-
var title = util.getTitle(event);
48+
var title = util.extractTitle(event);
4849
var repoName = event.repo!.name;
49-
var issueNumber = util.getIssueNumber(event);
50+
var issueNumber = util.extractIssueNumber(event);
5051

5152
return '- ($date): $action "$title" ([$repoName/$issueNumber]($url))';
5253
}

command_line/lib/src/options.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,11 @@ class Options {
4444
enum Interval {
4545
day,
4646
week,
47-
month,
47+
month;
48+
49+
Duration get duration => switch (this) {
50+
Interval.day => const Duration(days: 1),
51+
Interval.week => const Duration(days: 7),
52+
Interval.month => const Duration(days: 30),
53+
};
4854
}

command_line/lib/src/util.dart

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,25 @@ import 'package:github/github.dart';
66

77
import 'options.dart';
88

9-
String? getAction(Event event) {
10-
return event.payload!['action'];
11-
}
12-
13-
String? getUrl(Event event) {
14-
var type = event.type;
15-
16-
if (type == 'PullRequestEvent') {
17-
return event.payload!['pull_request']['html_url'];
18-
}
19-
20-
if (type == 'IssuesEvent') {
21-
return event.payload!['issue']['html_url'];
22-
}
23-
24-
return null;
25-
}
26-
27-
String? getTitle(Event event) {
28-
var type = event.type;
29-
30-
if (type == 'PullRequestEvent') {
31-
return event.payload!['pull_request']['title'];
32-
}
33-
34-
if (type == 'IssuesEvent') {
35-
return event.payload!['issue']['title'];
36-
}
37-
38-
return null;
39-
}
40-
41-
int? getIssueNumber(Event event) {
42-
var type = event.type;
43-
44-
if (type == 'PullRequestEvent') {
45-
return event.payload!['pull_request']['number'];
46-
}
47-
48-
if (type == 'IssuesEvent') {
49-
return event.payload!['issue']['number'];
50-
}
51-
52-
return null;
53-
}
54-
55-
bool isTooOld(DateTime? date, Interval interval) {
56-
var now = DateTime.now();
57-
switch (interval) {
58-
case Interval.day:
59-
return date!.isBefore(now.subtract(Duration(days: 1)));
60-
case Interval.week:
61-
return date!.isBefore(now.subtract(Duration(days: 7)));
62-
case Interval.month:
63-
return date!.isBefore(now.subtract(Duration(days: 30)));
64-
default:
65-
return true;
66-
}
67-
}
9+
String? extractAction(Event event) => event.payload!['action'];
10+
11+
String? extractUrl(Event event) => switch (event.type) {
12+
'PullRequestEvent' => event.payload!['pull_request']['html_url'],
13+
'IssuesEvent' => event.payload!['issue']['html_url'],
14+
_ => null,
15+
};
16+
17+
String? extractTitle(Event event) => switch (event.type) {
18+
'PullRequestEvent' => event.payload!['pull_request']['title'],
19+
'IssuesEvent' => event.payload!['issue']['title'],
20+
_ => null,
21+
};
22+
23+
int? extractIssueNumber(Event event) => switch (event.type) {
24+
'PullRequestEvent' => event.payload!['pull_request']['number'],
25+
'IssuesEvent' => event.payload!['issue']['number'],
26+
_ => null,
27+
};
28+
29+
bool isTooOld(DateTime? date, Interval interval) =>
30+
date?.isBefore(DateTime.now().subtract(interval.duration)) ?? true;

command_line/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: >-
77
publish_to: none
88

99
environment:
10-
sdk: ^3.4.0
10+
sdk: ^3.5.0
1111

1212
dependencies:
1313
args: ^2.5.0
@@ -17,9 +17,9 @@ dependencies:
1717

1818
dev_dependencies:
1919
build_cli: ^2.2.3
20-
build_runner: ^2.4.10
21-
lints: ^4.0.0
22-
test: ^1.25.0
20+
build_runner: ^2.4.13
21+
lints: ^5.0.0
22+
test: ^1.25.8
2323

2424
executables:
2525
github_activity: github_activity

enhanced_enums/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ description: Samples that demonstrates the enhanced enums syntax
55
publish_to: none
66

77
environment:
8-
sdk: ^3.4.0
8+
sdk: ^3.5.0
99

1010
dev_dependencies:
11-
lints: ^4.0.0
12-
test: ^1.25.0
11+
lints: ^5.0.0
12+
test: ^1.25.8

extension_methods/lib/some_api.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
///
88
/// Imagine that this code is coming from a different package, so we can't
99
/// directly change it.
10-
library some_api;
10+
library;
1111

1212
final betty = Person('Betty Holberton', DateTime(1917, 3, 7));
1313

0 commit comments

Comments
 (0)