Skip to content

Commit

Permalink
fix: Replacing atty unmaintained dependency (#194)
Browse files Browse the repository at this point in the history
**Atty is replaced by std::io::IsTerminal**

Because atty has been unmaintained for 4 years, it is necessary to
update it in this case to std::io::IsTerminal, which is part of the
_Rust Standard Library_.
[Ref](https://doc.rust-lang.org/std/io/trait.IsTerminal.html)

_Changes:_

- File: cargo-near\src\commands\build_command\docker.rs
Description: Atty is replaced by std::io::IsTerminal

- File: cargo-near\src\common.rs
Description: Atty is replaced by std::io::IsTerminal

- File: cargo-near\cargo-near\src\main.rs
Description: Atty is replaced by std::io::IsTerminal

- File: cargo-near\Cargo.toml
Description: Atty is removed and env_logger is updated to 0.11.5 because
the previous version used atty.

- File: cargo-near\integration-tests\Cargo.toml
Description: env_logger is updated to 0.11.5 because the previous
version used atty.

Reference issue: [Potentially replace unmaintained libraries
ignored](near/near-sdk-rs#1203)
  • Loading branch information
MPSxDev authored Aug 6, 2024
1 parent 7a294ae commit 95013b8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions cargo-near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ camino = "1.1.1"
cargo_metadata = "0.18.1"
clap = { version = "4.0.18", features = ["derive", "env"] }
colored = "2.0"
env_logger = "0.11"
env_logger = "0.11.5"
log = "0.4"
rustc_version = "0.4"
serde = "1.0.197"
Expand All @@ -40,8 +40,6 @@ schemars = "0.8"
near-abi = { version = "0.4.0", features = ["__chunked-entries"] }
libloading = "0.8.3"
zstd = "0.13"
atty = "0.2.14"

color-eyre = "0.6"
inquire = "0.7"
strum = { version = "0.24", features = ["derive"] }
Expand Down
20 changes: 9 additions & 11 deletions cargo-near/src/commands/build_command/docker.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{
process::{id, Command, ExitStatus},
thread,
time::{Duration, SystemTime, UNIX_EPOCH},
};

use crate::{commands::build_command::NEP330_BUILD_ENVIRONMENT_ENV_KEY, common::ColorPreference};
use crate::{
commands::build_command::{NEP330_CONTRACT_PATH_ENV_KEY, SERVER_DISABLE_INTERACTIVE},
types::source_id,
util,
};
use std::{
io::IsTerminal,
process::{id, Command, ExitStatus},
thread,
time::{Duration, SystemTime, UNIX_EPOCH},
};

use color_eyre::eyre::ContextCompat;

Expand Down Expand Up @@ -152,11 +152,9 @@ impl super::BuildCommand {
"--workdir",
&container_paths.crate_path,
];

log::debug!("input device is a tty: {}", atty::is(atty::Stream::Stdin));
if atty::is(atty::Stream::Stdin)
&& std::env::var(SERVER_DISABLE_INTERACTIVE).is_err()
{
let stdin_is_terminal = std::io::stdin().is_terminal();
log::debug!("input device is a tty: {}", stdin_is_terminal);
if stdin_is_terminal && std::env::var(SERVER_DISABLE_INTERACTIVE).is_err() {
docker_args.push("-it");
}

Expand Down
3 changes: 2 additions & 1 deletion cargo-near/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io::IsTerminal;
use std::{env, str::FromStr};

use strum::{EnumDiscriminants, EnumIter, EnumMessage};
Expand Down Expand Up @@ -41,7 +42,7 @@ fn default_mode() -> ColorPreference {
match env::var("NO_COLOR") {
Ok(v) if v != "0" => ColorPreference::Never,
_ => {
if atty::is(atty::Stream::Stderr) {
if std::io::stderr().is_terminal() {
ColorPreference::Always
} else {
ColorPreference::Never
Expand Down
4 changes: 2 additions & 2 deletions cargo-near/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::env;
use std::io::Write;
use std::io::{IsTerminal, Write};

use cargo_near::commands::build_command::NEP330_BUILD_ENVIRONMENT_ENV_KEY;
use colored::Colorize;
Expand Down Expand Up @@ -45,7 +45,7 @@ fn main() -> CliResult {

match env::var("NO_COLOR") {
Ok(v) if v != "0" => colored::control::set_override(false),
_ => colored::control::set_override(atty::is(atty::Stream::Stderr)),
_ => colored::control::set_override(std::io::stderr().is_terminal()),
}

let config = near_cli_rs::config::Config::get_config_toml()?;
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ tokio = "1.0"
quote = "1.0"
near-workspaces = "0.11.0"
zstd = "0.13"
env_logger = "0.11"
env_logger = "0.11.5"
log = "0.4"

0 comments on commit 95013b8

Please sign in to comment.