Skip to content

Commit

Permalink
Replace atty::is(Stderr) with stdlib
Browse files Browse the repository at this point in the history
Summary:
`std::io::IsTerminal` was stabilized in 1.70. It is intended to be a drop in replacement for `atty::is(Stderr)`.

This codemod replaces all usages of `atty::is(Stderr)` with `stderr().is_terminal()`, importing the necessary paths.

It used this script (generated with assistance from Metamate):
```
#!/bin/bash

files=$(fbgs -sl "atty::is(atty::Stream::Stderr)" | arc linttool debugfilterpaths --take RUSTFMT)

for file in $files; do
  sed -i 's/atty::is(atty::Stream::Stderr)/stderr().is_terminal()/g' $file
done

for file in $files; do
  sed -i '1i use std::io::{stderr, IsTerminal};' $file
done
```

`arc f` was ran twice, followed by two invocations of `arc lint -e extra --take RUSTFIXDEPS`.

This script was a little naive though, and as a result, I had to manually move the newly added imports to the correct line. I ran lints again afterwards.

Reviewed By: Imxset21

Differential Revision: D46601192

fbshipit-source-id: 18ef53a9fa25cbd733ca81f16b2c13ce8c5ddb98
  • Loading branch information
edward-shen authored and facebook-github-bot committed Jun 14, 2023
1 parent e5c8785 commit 7dd028f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 0 additions & 1 deletion hermit-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
anyhow = "1.0.65"
atty = "0.2"
bincode = "1.3.3"
clap = { version = "3.2.25", features = ["derive", "env", "regex", "unicode", "wrap_help"] }
colored = "1.9"
Expand Down
4 changes: 3 additions & 1 deletion hermit-cli/src/bin/hermit/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

use std::fs::File;
use std::io;
use std::io::stderr;
use std::io::IsTerminal;

use tracing::metadata::LevelFilter;
use tracing::Subscriber;
Expand Down Expand Up @@ -63,7 +65,7 @@ pub fn stderr_subscriber(level: Option<LevelFilter>) -> impl Subscriber {
tracing_subscriber::fmt()
.with_env_filter(filter)
.with_writer(io::stderr)
.with_ansi(atty::is(atty::Stream::Stderr))
.with_ansi(stderr().is_terminal())
.finish()
}

Expand Down

0 comments on commit 7dd028f

Please sign in to comment.