blob: 51fdcd17a2d4fa7d7a72907219098d369bad0aed [file]
// Copyright (c) 2026, 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.
part of 'cli.dart';
final class _ValidateCommand extends _Base {
_ValidateCommand({required super.out, required super.err});
@override
String get name => 'validate';
@override
String get description =>
'Check that the code samples in markdown files are up to date, without '
'changing anything.';
@override
int run() {
checkNoPositionalArguments();
final outcome = updateDirectory(directory: directory, write: false);
final failed = report(outcome);
for (final MapEntry(key: file, value: count) in outcome.stale.entries) {
err.writeln('$file: error: $count code '
'${count == 1 ? 'block is' : 'blocks are'} out of date; run '
'`dart run snippets@ update`');
}
if (outcome.stale.isEmpty && !failed) {
final files = outcome.scanned == 1 ? 'file is' : 'files are';
out.writeln('${outcome.scanned} markdown $files up to date');
}
return failed || outcome.stale.isNotEmpty ? 1 : 0;
}
}