Files
adventofcode2025/lib/day1/command.dart

53 lines
1.2 KiB
Dart
Raw Normal View History

2025-12-01 14:35:11 -06:00
import "dart:convert";
import "dart:io";
import "package:args/command_runner.dart";
class Day1Command extends Command {
// The [name] and [description] properties must be defined by every
// subclass.
2025-11-30 12:02:28 -06:00
@override
final name = "day1";
2025-11-30 12:02:28 -06:00
@override
final description = "Run Advent of Code 2025 Day 1";
Day1Command() {
// we can add command specific arguments here.
// [argParser] is automatically created by the parent class.
}
// [run] may also return a Future.
@override
void run() {
// [argResults] is set before [run()] is called and contains the flags/options
// passed to this command.
2025-12-01 14:35:11 -06:00
print(argResults!.rest);
if (argResults!.rest.length != 1) {
print(
"Expected 1 positional arguments, found ${argResults!.rest.length}",
);
}
var fileName = argResults!.rest[0];
var inputFile = File(fileName);
var openFile = inputFile.openRead();
openFile
.transform(utf8.decoder)
.transform(LineSplitter())
.listen(
(String line) {
print('$line: ${line.length} bytes');
},
onDone: () {
print('File is now closed.');
},
onError: (e) {
print(e.toString());
},
);
}
}