Skip to content

Commit

Permalink
doctor: Split version str with .lines() to account for Windows' `\r…
Browse files Browse the repository at this point in the history
…\n` (#130)

On Windows at least `adb` prints it version string with carriage return;
leaving the `\r` in there (by only splitting on `\n`) and not trimming
the string causes us to print its version with a `\r` at the end,
clearing the whole line (i.e. it would print `adb     1.0.41\r` followed
by the path, and then only the path remains on this line).

Rust's `.lines()` implementation already takes care of this by splitting
(inclusively) on `\n` and trimming off that `\n` and _optionally also a
`\r`_ in the iterator before returning it to us.
  • Loading branch information
MarijnS95 authored Aug 26, 2023
1 parent 203d111 commit 0fe7e31
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion xbuild/src/command/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Check {
.output()?;
anyhow::ensure!(output.status.success(), "failed to run {}", self.name);
let output = std::str::from_utf8(&output.stdout)?;
if let Some(line) = output.split('\n').nth(version.row as _) {
if let Some(line) = output.lines().nth(version.row as _) {
let mut col = version.col as usize;
if line.starts_with("Apple ") || line.starts_with("Homebrew ") {
col += 1;
Expand Down

0 comments on commit 0fe7e31

Please sign in to comment.