[dartdev] Provide no installation feedback in dart installed
Updates `dart installed` to provide feedback if nothing is installed. If they didn't specify `--all` but there are inactive tools, provide a suggestion to specify the `--all` flag as well. Resolves https://github.com/dart-lang/sdk/issues/61626 Change-Id: I7d68fe91a29650c113047065e673e7a1139df847 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510020 Reviewed-by: Daco Harkes <dacoharkes@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
7c3c71ae4d
commit
44bb92f49a
@@ -12,6 +12,10 @@ import 'package:pub_formats/pub_formats.dart';
|
||||
class InstalledCommand extends DartdevCommand {
|
||||
static const cmdName = 'installed';
|
||||
static const cmdDescription = 'List globally installed Dart CLI tools.';
|
||||
static const noToolsInstalledMessage = 'No Dart CLI tools installed.';
|
||||
static const noActiveToolsInstalledMessage =
|
||||
'No active Dart CLI tools installed. '
|
||||
'Run "dart installed --all" to show inactive tools.';
|
||||
|
||||
@override
|
||||
CommandCategory get commandCategory => CommandCategory.global;
|
||||
@@ -34,11 +38,21 @@ on `PATH` are non-active.''',
|
||||
final all = argResults.flag('all');
|
||||
|
||||
final installedPackages = getInstalledPackages();
|
||||
for (final package in installedPackages) {
|
||||
if (package.installed == Installed.not && !all) {
|
||||
continue;
|
||||
final packagesToShow = [
|
||||
for (final package in installedPackages)
|
||||
if (all || package.installed != Installed.not) package,
|
||||
];
|
||||
|
||||
if (packagesToShow.isEmpty) {
|
||||
if (all || installedPackages.isEmpty) {
|
||||
print(noToolsInstalledMessage);
|
||||
} else {
|
||||
print(noActiveToolsInstalledMessage);
|
||||
}
|
||||
} else {
|
||||
for (final package in packagesToShow) {
|
||||
print(package.toString());
|
||||
}
|
||||
print(package.toString());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartdev/src/commands/installed.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:pub_formats/pub_formats.dart';
|
||||
import 'package:test/test.dart';
|
||||
@@ -154,6 +155,67 @@ Run "dart help" to see global options.
|
||||
});
|
||||
}
|
||||
|
||||
skippableTest(
|
||||
'dart installed with no installations',
|
||||
timeout: longTimeout,
|
||||
() async {
|
||||
await inTempDir((tempUri) async {
|
||||
final binDir = Directory.fromUri(tempUri.resolve('install/bin'));
|
||||
|
||||
final environment = {
|
||||
_dartDirectoryEnvKey: tempUri.toFilePath(),
|
||||
'PATH':
|
||||
'${binDir.path}$_pathEnvVarSeparator'
|
||||
'${Platform.environment['PATH']!}',
|
||||
};
|
||||
|
||||
Future<RunProcessResult> runInstalled([
|
||||
List<String> arguments = const [],
|
||||
]) => _runDartdev(
|
||||
fromDartdevSource,
|
||||
'installed',
|
||||
arguments,
|
||||
null,
|
||||
environment,
|
||||
);
|
||||
|
||||
final emptyResult = await runInstalled();
|
||||
expect(
|
||||
emptyResult.stdout.trim(),
|
||||
equals(InstalledCommand.noToolsInstalledMessage),
|
||||
);
|
||||
expect(emptyResult.stderr, isEmpty);
|
||||
|
||||
final emptyAllResult = await runInstalled(['--all']);
|
||||
expect(
|
||||
emptyAllResult.stdout.trim(),
|
||||
equals(InstalledCommand.noToolsInstalledMessage),
|
||||
);
|
||||
expect(emptyAllResult.stderr, isEmpty);
|
||||
|
||||
await _runDartdev(
|
||||
fromDartdevSource,
|
||||
'install',
|
||||
[_package2Dir.path],
|
||||
null,
|
||||
environment,
|
||||
);
|
||||
|
||||
// Delete the bin directory to inactivate the installed tool.
|
||||
if (binDir.existsSync()) {
|
||||
binDir.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
final inactiveResult = await runInstalled();
|
||||
expect(
|
||||
inactiveResult.stdout.trim(),
|
||||
equals(InstalledCommand.noActiveToolsInstalledMessage),
|
||||
);
|
||||
expect(inactiveResult.stderr, isEmpty);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
final argumentss = [
|
||||
(null, [_packageForTest]),
|
||||
(null, [_packageForTest, _packageVersion]),
|
||||
@@ -735,7 +797,10 @@ void main(List<String> args) async {
|
||||
null,
|
||||
environment,
|
||||
);
|
||||
expect(await runInstalled(), hasLength(0));
|
||||
expect(
|
||||
await runInstalled(),
|
||||
equals([InstalledCommand.noToolsInstalledMessage]),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user