Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build, update deps, clean up CLI samples #223

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Created with package:mono_repo v6.6.1
# Created with package:mono_repo v6.6.2
name: Dart CI
on:
push:
Expand Down Expand Up @@ -33,20 +33,20 @@ jobs:
name: Checkout repository
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- name: mono_repo self validate
run: dart pub global activate mono_repo 6.6.1
run: dart pub global activate mono_repo 6.6.2
- name: mono_repo self validate
run: dart pub global run mono_repo generate --validate
job_002:
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 .`"
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 .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
with:
path: "~/.pub-cache/hosted"
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"
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"
restore-keys: |
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
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
os:ubuntu-latest;pub-cache-hosted;sdk:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
Expand Down Expand Up @@ -111,15 +111,15 @@ jobs:
run: dart analyze --fatal-infos .
if: "always() && steps.ffi_structs_pub_upgrade.conclusion == 'success'"
working-directory: ffi/structs
- id: ffi_system-command_pub_upgrade
name: "ffi/system-command; dart pub upgrade"
- id: ffi_system_command_pub_upgrade
name: ffi/system_command; dart pub upgrade
run: dart pub upgrade
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: ffi/system-command
- name: "ffi/system-command; dart analyze --fatal-infos ."
working-directory: ffi/system_command
- name: "ffi/system_command; dart analyze --fatal-infos ."
run: dart analyze --fatal-infos .
if: "always() && steps.ffi_system-command_pub_upgrade.conclusion == 'success'"
working-directory: ffi/system-command
if: "always() && steps.ffi_system_command_pub_upgrade.conclusion == 'success'"
working-directory: ffi/system_command
- id: ffi_test_utils_pub_upgrade
name: ffi/test_utils; dart pub upgrade
run: dart pub upgrade
Expand Down Expand Up @@ -195,16 +195,16 @@ jobs:
needs:
- job_001
job_003:
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 .`"
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 .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
with:
path: "~/.pub-cache/hosted"
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"
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"
restore-keys: |
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
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
os:ubuntu-latest;pub-cache-hosted;sdk:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
Expand Down Expand Up @@ -269,15 +269,15 @@ jobs:
run: "dart format --output=none --set-exit-if-changed ."
if: "always() && steps.ffi_structs_pub_upgrade.conclusion == 'success'"
working-directory: ffi/structs
- id: ffi_system-command_pub_upgrade
name: "ffi/system-command; dart pub upgrade"
- id: ffi_system_command_pub_upgrade
name: ffi/system_command; dart pub upgrade
run: dart pub upgrade
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: ffi/system-command
- name: "ffi/system-command; dart format --output=none --set-exit-if-changed ."
working-directory: ffi/system_command
- name: "ffi/system_command; dart format --output=none --set-exit-if-changed ."
run: "dart format --output=none --set-exit-if-changed ."
if: "always() && steps.ffi_system-command_pub_upgrade.conclusion == 'success'"
working-directory: ffi/system-command
if: "always() && steps.ffi_system_command_pub_upgrade.conclusion == 'success'"
working-directory: ffi/system_command
- id: ffi_test_utils_pub_upgrade
name: ffi/test_utils; dart pub upgrade
run: dart pub upgrade
Expand Down Expand Up @@ -353,16 +353,16 @@ jobs:
needs:
- job_001
job_004:
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 .`"
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 .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
with:
path: "~/.pub-cache/hosted"
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"
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"
restore-keys: |
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
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
os:ubuntu-latest;pub-cache-hosted;sdk:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
Expand Down Expand Up @@ -427,15 +427,15 @@ jobs:
run: dart analyze --fatal-infos .
if: "always() && steps.ffi_structs_pub_upgrade.conclusion == 'success'"
working-directory: ffi/structs
- id: ffi_system-command_pub_upgrade
name: "ffi/system-command; dart pub upgrade"
- id: ffi_system_command_pub_upgrade
name: ffi/system_command; dart pub upgrade
run: dart pub upgrade
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: ffi/system-command
- name: "ffi/system-command; dart analyze --fatal-infos ."
working-directory: ffi/system_command
- name: "ffi/system_command; dart analyze --fatal-infos ."
run: dart analyze --fatal-infos .
if: "always() && steps.ffi_system-command_pub_upgrade.conclusion == 'success'"
working-directory: ffi/system-command
if: "always() && steps.ffi_system_command_pub_upgrade.conclusion == 'success'"
working-directory: ffi/system_command
- id: ffi_test_utils_pub_upgrade
name: ffi/test_utils; dart pub upgrade
run: dart pub upgrade
Expand Down Expand Up @@ -502,16 +502,16 @@ jobs:
needs:
- job_001
job_005:
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 .`"
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 .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
with:
path: "~/.pub-cache/hosted"
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"
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"
restore-keys: |
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
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
os:ubuntu-latest;pub-cache-hosted;sdk:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
Expand Down Expand Up @@ -576,15 +576,15 @@ jobs:
run: "dart format --output=none --set-exit-if-changed ."
if: "always() && steps.ffi_structs_pub_upgrade.conclusion == 'success'"
working-directory: ffi/structs
- id: ffi_system-command_pub_upgrade
name: "ffi/system-command; dart pub upgrade"
- id: ffi_system_command_pub_upgrade
name: ffi/system_command; dart pub upgrade
run: dart pub upgrade
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: ffi/system-command
- name: "ffi/system-command; dart format --output=none --set-exit-if-changed ."
working-directory: ffi/system_command
- name: "ffi/system_command; dart format --output=none --set-exit-if-changed ."
run: "dart format --output=none --set-exit-if-changed ."
if: "always() && steps.ffi_system-command_pub_upgrade.conclusion == 'success'"
working-directory: ffi/system-command
if: "always() && steps.ffi_system_command_pub_upgrade.conclusion == 'success'"
working-directory: ffi/system_command
- id: ffi_test_utils_pub_upgrade
name: ffi/test_utils; dart pub upgrade
run: dart pub upgrade
Expand Down
3 changes: 3 additions & 0 deletions command_line/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Command line app sample

This sample demonstrates how to parse command line options into Dart objects
using [`package:build_cli_annotations`][build-cli], read environment variables,
use third-party packages like `package:github` and use core library APIs like
DateTime.

## Adding new CLI options

To add new command line options to `lib/src/options.dart`, update the `Options`
class and re-run `build_runner`:

Expand All @@ -13,6 +15,7 @@ dart run build_runner build
```

## About this project

`bin/github_activity.dart` is a command line application that fetches stats for
a GitHub user and prints them to the console.

Expand Down
21 changes: 11 additions & 10 deletions command_line/lib/src/formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ abstract class EventFormatter {
String format(Event event);
}

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

const DefaultEventFormatter();

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

return '$date: $username $action $url';
}
}

class MarkdownEventFormatter implements EventFormatter {
static final dateFormat = DateFormat('EEE, M/d/y');
static final DateFormat dateFormat = DateFormat('EEE, M/d/y');

@override
String format(Event event) {
var date = dateFormat.format(event.createdAt!.toLocal());
var type = event.type;
var action = util.getAction(event);
var url = util.getUrl(event);
var action = util.extractAction(event);
var url = util.extractUrl(event);
if (url == null) {
return '- ($date): [$type]';
}
var title = util.getTitle(event);
var title = util.extractTitle(event);
var repoName = event.repo!.name;
var issueNumber = util.getIssueNumber(event);
var issueNumber = util.extractIssueNumber(event);

return '- ($date): $action "$title" ([$repoName/$issueNumber]($url))';
}
Expand Down
8 changes: 7 additions & 1 deletion command_line/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ class Options {
enum Interval {
day,
week,
month,
month;

Duration get duration => switch (this) {
Interval.day => const Duration(days: 1),
Interval.week => const Duration(days: 7),
Interval.month => const Duration(days: 30),
};
}
81 changes: 22 additions & 59 deletions command_line/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,25 @@ import 'package:github/github.dart';

import 'options.dart';

String? getAction(Event event) {
return event.payload!['action'];
}

String? getUrl(Event event) {
var type = event.type;

if (type == 'PullRequestEvent') {
return event.payload!['pull_request']['html_url'];
}

if (type == 'IssuesEvent') {
return event.payload!['issue']['html_url'];
}

return null;
}

String? getTitle(Event event) {
var type = event.type;

if (type == 'PullRequestEvent') {
return event.payload!['pull_request']['title'];
}

if (type == 'IssuesEvent') {
return event.payload!['issue']['title'];
}

return null;
}

int? getIssueNumber(Event event) {
var type = event.type;

if (type == 'PullRequestEvent') {
return event.payload!['pull_request']['number'];
}

if (type == 'IssuesEvent') {
return event.payload!['issue']['number'];
}

return null;
}

bool isTooOld(DateTime? date, Interval interval) {
var now = DateTime.now();
switch (interval) {
case Interval.day:
return date!.isBefore(now.subtract(Duration(days: 1)));
case Interval.week:
return date!.isBefore(now.subtract(Duration(days: 7)));
case Interval.month:
return date!.isBefore(now.subtract(Duration(days: 30)));
default:
return true;
}
}
String? extractAction(Event event) => event.payload!['action'];

String? extractUrl(Event event) => switch (event.type) {
'PullRequestEvent' => event.payload!['pull_request']['html_url'],
'IssuesEvent' => event.payload!['issue']['html_url'],
_ => null,
};

String? extractTitle(Event event) => switch (event.type) {
'PullRequestEvent' => event.payload!['pull_request']['title'],
'IssuesEvent' => event.payload!['issue']['title'],
_ => null,
};

int? extractIssueNumber(Event event) => switch (event.type) {
'PullRequestEvent' => event.payload!['pull_request']['number'],
'IssuesEvent' => event.payload!['issue']['number'],
_ => null,
};

bool isTooOld(DateTime? date, Interval interval) =>
date?.isBefore(DateTime.now().subtract(interval.duration)) ?? true;
8 changes: 4 additions & 4 deletions command_line/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: >-
publish_to: none

environment:
sdk: ^3.4.0
sdk: ^3.5.0

dependencies:
args: ^2.5.0
Expand All @@ -17,9 +17,9 @@ dependencies:

dev_dependencies:
build_cli: ^2.2.3
build_runner: ^2.4.10
lints: ^4.0.0
test: ^1.25.0
build_runner: ^2.4.13
lints: ^5.0.0
test: ^1.25.8

executables:
github_activity: github_activity
6 changes: 3 additions & 3 deletions enhanced_enums/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ description: Samples that demonstrates the enhanced enums syntax
publish_to: none

environment:
sdk: ^3.4.0
sdk: ^3.5.0

dev_dependencies:
lints: ^4.0.0
test: ^1.25.0
lints: ^5.0.0
test: ^1.25.8
2 changes: 1 addition & 1 deletion extension_methods/lib/some_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
///
/// Imagine that this code is coming from a different package, so we can't
/// directly change it.
library some_api;
library;

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

Expand Down
Loading