Skip to content
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
1 change: 0 additions & 1 deletion .github/workflows/very_good_cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ jobs:
pana:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/pana.yml@v1
with:
min_score: 150 # Update minimum score to 160 once we have the CLI up to date.
pana_version: 0.22.21
5 changes: 1 addition & 4 deletions lib/src/cli/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ abstract class ProcessOverrides {
}

/// Runs [body] in a fresh [Zone] using the provided overrides.
static R runZoned<R>(
R Function() body, {
RunProcess? runProcess,
}) {
static R runZoned<R>(R Function() body, {RunProcess? runProcess}) {
final overrides = _ProcessOverridesScope(runProcess);
return _asyncRunZoned(body, zoneValues: {_token: overrides});
}
Expand Down
4 changes: 1 addition & 3 deletions lib/src/cli/dart_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ part of 'cli.dart';
/// Dart CLI
class Dart {
/// Determine whether dart is installed.
static Future<bool> installed({
required Logger logger,
}) async {
static Future<bool> installed({required Logger logger}) async {
try {
await _Cmd.run('dart', ['--version'], logger: logger);
return true;
Expand Down
69 changes: 27 additions & 42 deletions lib/src/cli/flutter_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ class _CoverageMetrics {
String? excludeFromCoverage,
) {
final glob = excludeFromCoverage != null ? Glob(excludeFromCoverage) : null;
return records.fold<_CoverageMetrics>(
const _CoverageMetrics._(),
(current, record) {
final found = record.lines?.found ?? 0;
final hit = record.lines?.hit ?? 0;
if (glob != null && record.file != null) {
if (glob.matches(record.file!)) {
return current;
}
return records.fold<_CoverageMetrics>(const _CoverageMetrics._(), (
current,
record,
) {
final found = record.lines?.found ?? 0;
final hit = record.lines?.hit ?? 0;
if (glob != null && record.file != null) {
if (glob.matches(record.file!)) {
return current;
}
return _CoverageMetrics._(
totalFound: current.totalFound + found,
totalHits: current.totalHits + hit,
);
},
);
}
return _CoverageMetrics._(
totalFound: current.totalFound + found,
totalHits: current.totalHits + hit,
);
});
}

final int totalHits;
Expand All @@ -119,9 +119,7 @@ typedef GeneratorBuilder = Future<MasonGenerator> Function(MasonBundle);
/// Flutter CLI
class Flutter {
/// Determine whether flutter is installed.
static Future<bool> installed({
required Logger logger,
}) async {
static Future<bool> installed({required Logger logger}) async {
try {
await _Cmd.run('flutter', ['--version'], logger: logger);
return true;
Expand Down Expand Up @@ -213,14 +211,10 @@ class Flutter {
? '.'
: '.${p.context.separator}$relativePath';

stdout?.call(
'Running "flutter test" in $path ...\n',
);
stdout?.call('Running "flutter test" in $path ...\n');

if (!Directory(p.join(target.dir.absolute.path, 'test')).existsSync()) {
stdout?.call(
'No test folder found in $path\n',
);
stdout?.call('No test folder found in $path\n');
return ExitCode.success.code;
}

Expand Down Expand Up @@ -333,10 +327,7 @@ Future<void> _verifyGitDependencies(

await Future.wait(
gitDependencies.map(
(dependency) => Git.reachable(
dependency.url,
logger: logger,
),
(dependency) => Git.reachable(dependency.url, logger: logger),
),
);
}
Expand Down Expand Up @@ -408,13 +399,11 @@ Future<int> _flutterTest({
Stream.periodic(
const Duration(seconds: 1),
(computationCount) => computationCount,
).listen(
(tick) {
if (completer.isCompleted) return;
final timeElapsed = Duration(seconds: tick).formatted();
stdout('$clearLine$timeElapsed ...');
},
);
).listen((tick) {
if (completer.isCompleted) return;
final timeElapsed = Duration(seconds: tick).formatted();
stdout('$clearLine$timeElapsed ...');
});

late final StreamSubscription<TestEvent> subscription;
late final StreamSubscription<ProcessSignal> sigintWatchSubscription;
Expand All @@ -429,10 +418,7 @@ Future<int> _flutterTest({
subscription =
testRunner(
workingDirectory: cwd,
arguments: [
if (collectCoverage) '--coverage',
...?arguments,
],
arguments: [if (collectCoverage) '--coverage', ...?arguments],
runInShell: true,
).listen(
(event) {
Expand Down Expand Up @@ -586,9 +572,8 @@ String? _topGroupName(Test test, Map<int, TestGroup> groups) => test.groupIDs
.map((groupID) => groups[groupID]?.name)
.firstWhereOrNull((groupName) => groupName?.isNotEmpty ?? false);

Future<void> _cleanupOptimizerFile(String cwd) async => File(
p.join(cwd, 'test', _testOptimizerFileName),
).delete().ignore();
Future<void> _cleanupOptimizerFile(String cwd) async =>
File(p.join(cwd, 'test', _testOptimizerFileName)).delete().ignore();

final int _lineLength = () {
try {
Expand Down
15 changes: 6 additions & 9 deletions lib/src/cli/git_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ Make sure the remote exists and you have the correct access rights.''';
/// Git CLI
class Git {
/// Determine whether the [remote] is reachable.
static Future<void> reachable(
Uri remote, {
required Logger logger,
}) async {
static Future<void> reachable(Uri remote, {required Logger logger}) async {
try {
await _Cmd.run(
'git',
['ls-remote', '$remote', '--exit-code'],
logger: logger,
);
await _Cmd.run('git', [
'ls-remote',
'$remote',
'--exit-code',
], logger: logger);
} on Exception catch (_) {
throw UnreachableGitDependency(remote: remote);
}
Expand Down
17 changes: 5 additions & 12 deletions lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ class VeryGoodCommandRunner extends CompletionCommandRunner<int> {
_environment = environment ?? Platform.environment,
super('very_good', '🦄 A Very Good Command-Line Interface') {
argParser
..addFlag(
'version',
negatable: false,
help: 'Print the current version.',
)
..addFlag('version', negatable: false, help: 'Print the current version.')
..addFlag(
'verbose',
help: 'Noisy logging, including all shell commands executed.',
Expand Down Expand Up @@ -139,22 +135,19 @@ class VeryGoodCommandRunner extends CompletionCommandRunner<int> {
if (!isUpToDate) {
_logger
..info('')
..info(
'''
..info('''
${lightYellow.wrap('Update available!')} ${lightCyan.wrap(packageVersion)} \u2192 ${lightCyan.wrap(latestVersion)}
${lightYellow.wrap('Changelog:')} ${lightCyan.wrap('https://github.com/verygoodopensource/very_good_cli/releases/tag/v$latestVersion')}
Run ${lightCyan.wrap('very_good update')} to update''',
);
Run ${lightCyan.wrap('very_good update')} to update''');
}
} on Exception catch (_) {}
}

void _showThankYou() {
if (environment.containsKey('CI')) return;

final versionFile = File(
path.join(_configDir.path, 'version'),
)..createSync(recursive: true);
final versionFile = File(path.join(_configDir.path, 'version'))
..createSync(recursive: true);

if (versionFile.readAsStringSync() == packageVersion) return;
versionFile.writeAsStringSync(packageVersion);
Expand Down
4 changes: 1 addition & 3 deletions lib/src/commands/create/commands/create_subcommand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ mixin MultiTemplates on CreateSubCommand {
final templateName =
argResults['template'] as String? ?? defaultTemplateName;

return templates.firstWhere(
(element) => element.name == templateName,
);
return templates.firstWhere((element) => element.name == templateName);
}
}

Expand Down
8 changes: 2 additions & 6 deletions lib/src/commands/packages/commands/check/check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ import 'package:very_good_cli/src/commands/packages/commands/check/commands/comm
/// {@endtemplate}
class PackagesCheckCommand extends Command<int> {
/// {@macro packages_check_command}
PackagesCheckCommand({
Logger? logger,
}) {
addSubcommand(
PackagesCheckLicensesCommand(logger: logger),
);
PackagesCheckCommand({Logger? logger}) {
addSubcommand(PackagesCheckLicensesCommand(logger: logger));
}

@override
Expand Down
42 changes: 18 additions & 24 deletions lib/src/commands/packages/commands/check/commands/licenses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import 'package:very_good_cli/src/pubspec_lock/pubspec_lock.dart';

/// Overrides the [package_config.findPackageConfig] function for testing.
@visibleForTesting
Future<package_config.PackageConfig?> Function(
Directory directory,
)?
Future<package_config.PackageConfig?> Function(Directory directory)?
findPackageConfigOverride;

/// Overrides the [detector.detectLicense] function for testing.
Expand Down Expand Up @@ -72,9 +70,8 @@ typedef _BannedDependencyLicenseMap = Map<String, Set<String>>;
/// {@endtemplate}
class PackagesCheckLicensesCommand extends Command<int> {
/// {@macro packages_check_licenses_command}
PackagesCheckLicensesCommand({
Logger? logger,
}) : _logger = logger ?? Logger() {
PackagesCheckLicensesCommand({Logger? logger})
: _logger = logger ?? Logger() {
argParser
..addFlag(
'ignore-retrieval-failures',
Expand Down Expand Up @@ -102,10 +99,7 @@ class PackagesCheckLicensesCommand extends Command<int> {
'allowed',
help: 'Only allow the use of certain licenses.',
)
..addMultiOption(
'forbidden',
help: 'Deny the use of certain licenses.',
)
..addMultiOption('forbidden', help: 'Deny the use of certain licenses.')
..addMultiOption(
'skip-packages',
help: 'Skip packages from having their licenses checked.',
Expand Down Expand Up @@ -459,20 +453,20 @@ String _composeReport({
}

String _composeBannedReport(_BannedDependencyLicenseMap bannedDependencies) {
final bannedDependenciesList = bannedDependencies.entries.fold(
<String>[],
(previousValue, element) {
final dependencyName = element.key;
final dependencyLicenses = element.value;

final text =
'$dependencyName (${link(
uri: pubLicenseUri(dependencyName),
message: dependencyLicenses.toList().stringify(),
)})';
return previousValue..add(text);
},
);
final bannedDependenciesList = bannedDependencies.entries.fold(<String>[], (
previousValue,
element,
) {
final dependencyName = element.key;
final dependencyLicenses = element.value;
final hyperlink = link(
uri: pubLicenseUri(dependencyName),
message: dependencyLicenses.toList().stringify(),
);

final text = '$dependencyName ($hyperlink)';
return previousValue..add(text);
});
final bannedLicenseTypes = bannedDependencies.values.fold(<String>{}, (
previousValue,
licenses,
Expand Down
6 changes: 2 additions & 4 deletions lib/src/commands/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ class TestCommand extends Command<int> {
final recursive = _argResults['recursive'] as bool;

if (!recursive && !pubspec.existsSync()) {
_logger.err(
'''
_logger.err('''
Could not find a pubspec.yaml in $targetPath.
This command should be run from the root of your Flutter project.''',
);
This command should be run from the root of your Flutter project.''');
return ExitCode.noInput.code;
}

Expand Down
8 changes: 3 additions & 5 deletions lib/src/commands/update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import 'package:very_good_cli/src/version.dart';
/// {@endtemplate}
class UpdateCommand extends Command<int> {
/// {@macro update_command}
UpdateCommand({
required Logger logger,
PubUpdater? pubUpdater,
}) : _logger = logger,
_pubUpdater = pubUpdater ?? PubUpdater();
UpdateCommand({required Logger logger, PubUpdater? pubUpdater})
: _logger = logger,
_pubUpdater = pubUpdater ?? PubUpdater();

final Logger _logger;
final PubUpdater _pubUpdater;
Expand Down
Loading