-
Notifications
You must be signed in to change notification settings - Fork 7
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
[puppy] Introduce a package for misc Dart CLI tools #335
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bb458c2
[puppy] Introduce a package for misc Dart CLI tools
kevmoo e42ed2d
update labels
kevmoo 969e7a7
Merge remote-tracking branch 'origin/HEAD' into puppy
kevmoo 030feb0
review notes
kevmoo 9e00209
fix licence things
kevmoo 1a2998e
fix nits
kevmoo 0f221b2
add license fun
kevmoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: package:puppy | ||
|
||
permissions: read-all | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- '.github/workflows/puppy.yml' | ||
- 'pkgs/puppy/**' | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- '.github/workflows/puppy.yml' | ||
- 'pkgs/puppy/**' | ||
schedule: | ||
- cron: '0 0 * * 0' # weekly | ||
|
||
defaults: | ||
run: | ||
working-directory: pkgs/puppy | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
sdk: [3.6, dev] | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 | ||
with: | ||
sdk: ${{ matrix.sdk }} | ||
|
||
- run: dart pub get | ||
- run: dart analyze --fatal-infos | ||
- run: dart format --output=none --set-exit-if-changed . | ||
if: ${{ matrix.sdk == 'dev' }} | ||
# TODO: enable when there are tests! | ||
#- run: dart test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Activate locally using: | ||
|
||
```console | ||
cd <puppy pkg path> | ||
dart pub global activate --source=path . | ||
``` | ||
|
||
### Commands | ||
|
||
- `run`: runs a command in every directory containing | ||
`pubspec.yaml`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:dart_flutter_team_lints/analysis_options.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:args/command_runner.dart'; | ||
import 'package:puppy/src/constants.dart'; | ||
import 'package:puppy/src/map_command.dart'; | ||
|
||
Future<void> main(List<String> args) async { | ||
var runner = CommandRunner<void>(cmdName, 'Dart repository management tools.') | ||
..addCommand(MapCommand()); | ||
|
||
await runner.run(args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
const cmdName = 'puppy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:args/command_runner.dart'; | ||
import 'package:build_cli_annotations/build_cli_annotations.dart'; | ||
import 'package:io/ansi.dart'; | ||
|
||
import 'constants.dart'; | ||
|
||
part 'map_command.g.dart'; | ||
|
||
class MapCommand extends _$MapArgsCommand<void> { | ||
@override | ||
String get description => | ||
'Run the provided command in each subdirectory containing ' | ||
'`pubspec.yaml`.'; | ||
|
||
@override | ||
String get name => 'map'; | ||
|
||
@override | ||
Future<void>? run() async { | ||
await _doMap(_options); | ||
} | ||
} | ||
|
||
@CliOptions(createCommand: true) | ||
class MapArgs { | ||
@CliOption(abbr: 'd', help: 'Keep looking for "nested" pubspec files.') | ||
final bool deep; | ||
|
||
final List<String> rest; | ||
|
||
MapArgs({ | ||
this.deep = false, | ||
required this.rest, | ||
}) { | ||
if (rest.isEmpty) { | ||
throw UsageException( | ||
'Missing command to invoke!', | ||
'$cmdName map [--deep] <command to invoke>', | ||
); | ||
} | ||
} | ||
} | ||
|
||
Future<void> _doMap(MapArgs args) async { | ||
final exe = args.rest.first; | ||
final extraArgs = args.rest.skip(1).toList(); | ||
|
||
final exits = <String, int>{}; | ||
|
||
Future<void> inspectDirectory(Directory dir, {required bool deep}) async { | ||
final pubspecs = dir | ||
.listSync() | ||
.whereType<File>() | ||
.where((element) => element.uri.pathSegments.last == 'pubspec.yaml') | ||
.toList(); | ||
|
||
final pubspecHere = pubspecs.isNotEmpty; | ||
if (pubspecHere) { | ||
print(green.wrap(dir.path)); | ||
final proc = await Process.start( | ||
exe, | ||
extraArgs, | ||
mode: ProcessStartMode.inheritStdio, | ||
workingDirectory: dir.path, | ||
); | ||
|
||
// TODO(kevmoo): display a summary of results on completion | ||
exits[dir.path] = await proc.exitCode; | ||
} | ||
|
||
if (!pubspecHere || deep) { | ||
for (var subDir in dir.listSync().whereType<Directory>().where( | ||
(element) => !element.uri.pathSegments | ||
.any((element) => element.startsWith('.')))) { | ||
await inspectDirectory(subDir, deep: deep); | ||
} | ||
} | ||
} | ||
|
||
await inspectDirectory(Directory.current, deep: args.deep); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: puppy | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ^3.6.0 | ||
|
||
dependencies: | ||
args: ^2.6.0 | ||
build_cli_annotations: ^2.1.0 | ||
io: ^1.0.5 | ||
|
||
dev_dependencies: | ||
build_cli: ^2.2.4 | ||
build_runner: ^2.4.14 | ||
dart_flutter_team_lints: ^3.0.0 | ||
|
||
executables: | ||
puppy: |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to pipe through command aliases here? If we wanted to instead support
puppy run
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh crap! I forgot! Just submit a PR to change that now.