Skip to content

Commit

Permalink
refactor: runCommand should just return stdout instead of Process (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp authored May 10, 2024
1 parent b34b9e4 commit 998a178
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
3 changes: 1 addition & 2 deletions native_doctor/lib/src/android_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ class AndroidSdkInfo {
final flutterCommand = flutterRoot != null
? path.join(flutterRoot, 'bin', 'flutter')
: 'flutter';
final result = await runCommand(
final json = await runCommand(
flutterCommand,
[
'config',
'--machine',
],
logger: logger,
);
final json = result.stdout as String;
final decoded = jsonDecode(json) as Map<String, dynamic>;
final javaHome = decoded['jdk-dir'] as String?;
final sdk = decoded['android-sdk'] as String?;
Expand Down
2 changes: 1 addition & 1 deletion native_doctor/lib/src/checkers/ndk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class NdkToolchainChecker extends ToolchainChecker {
logger: doctor.verboseLogger,
);
latestVersion = findBestNdkKversion(
sdkManagerOutput: list.stdout,
sdkManagerOutput: list,
minimumVersion: minimumVersion!,
);
if (latestVersion == null) {
Expand Down
4 changes: 2 additions & 2 deletions native_toolchain_rust_common/lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CommandFailedException implements Exception {
}
}

Future<ProcessResult> runCommand(
Future<String> runCommand(
String executable,
List<String> arguments, {
String? workingDirectory,
Expand Down Expand Up @@ -85,6 +85,6 @@ Future<ProcessResult> runCommand(
result: res,
);
} else {
return res;
return res.stdout as String;
}
}
6 changes: 1 addition & 5 deletions rustup/lib/src/installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class RustupInstaller {
String? cargoHome,
String? rustupHome,
}) async {
final process = await runCommand(
await runCommand(
_scriptPath(),
[
'--default-toolchain',
Expand All @@ -33,10 +33,6 @@ abstract class RustupInstaller {
},
logger: _logger,
);
final exitCode = process.exitCode;
if (exitCode != 0) {
throw Exception('Failed to install rustup');
}
}

Future<void> dispose();
Expand Down
9 changes: 4 additions & 5 deletions rustup/lib/src/rustup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class Rustup {
// To list all non-custom toolchains, we need to filter out lines that
// don't start with "stable", "beta", or "nightly".
Pattern nonCustom = RegExp(r"^(stable|beta|nightly)");
final lines = res.stdout
.toString()
final lines = res
.split('\n')
.where((e) => e.isNotEmpty && e.startsWith(nonCustom))
.map(extractToolchainName)
Expand All @@ -81,7 +80,7 @@ class Rustup {
return runCommand(['self', 'uninstall', '-y']);
}

Future<ProcessResult> runCommand(
Future<String> runCommand(
List<String> arguments, {
Map<String, String>? environment,
Logger? logger,
Expand Down Expand Up @@ -274,7 +273,7 @@ class RustupToolchain {

Future<Version> rustVersion() async {
final res = await rustup.runCommand(['run', name, 'rustc', '--version']);
final versionString = res.stdout.toString().split(' ')[1];
final versionString = res.split(' ')[1];
return Version.parse(versionString);
}

Expand All @@ -301,7 +300,7 @@ class RustupToolchain {
name,
'--installed',
]);
final lines = res.stdout.toString().split('\n').where((e) => e.isNotEmpty);
final lines = res.toString().split('\n').where((e) => e.isNotEmpty);
return lines
.map((e) => RustTarget.fromTriple(e))
.whereNotNull()
Expand Down

0 comments on commit 998a178

Please sign in to comment.