Skip to content

Commit

Permalink
review notes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Jan 10, 2025
1 parent 969e7a7 commit 030feb0
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 52 deletions.
4 changes: 2 additions & 2 deletions pkgs/puppy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cd <puppy pkg path>
dart pub global activate --source=path .
```

### Tools
### Commands

- `for_all_package_dirs`: runs a command in every directory containing
- `run`: runs a command in every directory containing
`pubspec.yaml`.
49 changes: 0 additions & 49 deletions pkgs/puppy/bin/for_all_package_dirs.dart

This file was deleted.

10 changes: 10 additions & 0 deletions pkgs/puppy/bin/puppy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:args/command_runner.dart';
import 'package:puppy/src/map_command.dart';

Future<void> main(List<String> args) async {
var runner = CommandRunner<void>(
'dgit', 'A dart implementation of distributed version control.')
..addCommand(MapCommand());

await runner.run(args);
}
86 changes: 86 additions & 0 deletions pkgs/puppy/lib/src/map_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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';

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!',
'puppy 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);
}
34 changes: 34 additions & 0 deletions pkgs/puppy/lib/src/map_command.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pkgs/puppy/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ 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:
for_all_package_dirs:
puppy:

0 comments on commit 030feb0

Please sign in to comment.