diff --git a/Cargo.lock b/Cargo.lock index 8502cbea2d..3e464ccddf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3149,6 +3149,7 @@ dependencies = [ name = "nym-bin-common" version = "0.3.0" dependencies = [ + "atty", "clap 4.1.11", "clap_complete", "clap_complete_fig", @@ -3502,7 +3503,6 @@ name = "nym-mixnode" version = "1.1.14" dependencies = [ "anyhow", - "atty", "bs58", "clap 4.1.11", "colored", diff --git a/clients/native/src/main.rs b/clients/native/src/main.rs index 48965e7c1a..cc862b2a88 100644 --- a/clients/native/src/main.rs +++ b/clients/native/src/main.rs @@ -4,7 +4,7 @@ use std::error::Error; use clap::{crate_name, crate_version, Parser}; -use nym_bin_common::logging::{banner, setup_logging}; +use nym_bin_common::logging::{maybe_print_banner, setup_logging}; use nym_network_defaults::setup_env; pub mod client; @@ -15,7 +15,7 @@ pub mod websocket; #[tokio::main] async fn main() -> Result<(), Box> { setup_logging(); - println!("{}", banner(crate_name!(), crate_version!())); + maybe_print_banner(crate_name!(), crate_version!()); let args = commands::Cli::parse(); setup_env(args.config_env_file.as_ref()); diff --git a/clients/socks5/src/main.rs b/clients/socks5/src/main.rs index 1c3d9b83d7..7125c0c042 100644 --- a/clients/socks5/src/main.rs +++ b/clients/socks5/src/main.rs @@ -4,7 +4,7 @@ use std::error::Error; use clap::{crate_name, crate_version, Parser}; -use nym_bin_common::logging::{banner, setup_logging}; +use nym_bin_common::logging::{maybe_print_banner, setup_logging}; use nym_network_defaults::setup_env; mod commands; @@ -13,7 +13,7 @@ pub mod error; #[tokio::main] async fn main() -> Result<(), Box> { setup_logging(); - println!("{}", banner(crate_name!(), crate_version!())); + maybe_print_banner(crate_name!(), crate_version!()); let args = commands::Cli::parse(); setup_env(args.config_env_file.as_ref()); diff --git a/common/bin-common/Cargo.toml b/common/bin-common/Cargo.toml index 40867d90d6..29fd632897 100644 --- a/common/bin-common/Cargo.toml +++ b/common/bin-common/Cargo.toml @@ -8,6 +8,7 @@ license = { workspace = true } repository = { workspace = true } [dependencies] +atty = "0.2" clap = { version = "4.0", features = ["derive"] } clap_complete = "4.0" clap_complete_fig = "4.0" diff --git a/common/bin-common/src/logging/mod.rs b/common/bin-common/src/logging/mod.rs index 27f7711e80..1562c91e8b 100644 --- a/common/bin-common/src/logging/mod.rs +++ b/common/bin-common/src/logging/mod.rs @@ -39,3 +39,9 @@ pub fn banner(crate_name: &str, crate_version: &str) -> String { "# ) } + +pub fn maybe_print_banner(crate_name: &str, crate_version: &str) { + if atty::is(atty::Stream::Stdout) { + println!("{}", banner(crate_name, crate_version)) + } +} diff --git a/gateway/src/main.rs b/gateway/src/main.rs index b17906d4f0..9ea8eb679d 100644 --- a/gateway/src/main.rs +++ b/gateway/src/main.rs @@ -5,9 +5,9 @@ use clap::{crate_name, crate_version, Parser}; use colored::Colorize; use lazy_static::lazy_static; use log::error; -use nym_bin_common::logging::setup_logging; +use nym_bin_common::build_information::BinaryBuildInformation; +use nym_bin_common::logging::{maybe_print_banner, setup_logging}; use nym_bin_common::output_format::OutputFormat; -use nym_bin_common::{build_information::BinaryBuildInformation, logging::banner}; use nym_network_defaults::setup_env; use std::error::Error; @@ -41,9 +41,7 @@ struct Cli { #[tokio::main] async fn main() -> Result<(), Box> { setup_logging(); - if atty::is(atty::Stream::Stdout) { - println!("{}", banner(crate_name!(), crate_version!())); - } + maybe_print_banner(crate_name!(), crate_version!()); let args = Cli::parse(); setup_env(args.config_env_file.as_ref()); diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index 5bfce1a43b..014f862b87 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -36,7 +36,6 @@ tokio = { version = "1.21.2", features = ["rt-multi-thread", "net", "signal"] } tokio-util = { version = "0.7.3", features = ["codec"] } toml = "0.5.8" url = { version = "2.2", features = ["serde"] } -atty = "0.2" ## internal nym-config = { path = "../common/config" } diff --git a/mixnode/src/main.rs b/mixnode/src/main.rs index e041c9ad08..e9f9f9f59c 100644 --- a/mixnode/src/main.rs +++ b/mixnode/src/main.rs @@ -7,8 +7,8 @@ extern crate rocket; use ::nym_config::defaults::setup_env; use clap::{crate_name, crate_version, Parser}; use lazy_static::lazy_static; -use nym_bin_common::logging::setup_logging; -use nym_bin_common::{build_information::BinaryBuildInformation, logging::banner}; +use nym_bin_common::build_information::BinaryBuildInformation; +use nym_bin_common::logging::{maybe_print_banner, setup_logging}; mod commands; mod config; @@ -43,9 +43,7 @@ pub fn cpu_cycles() { #[tokio::main] async fn main() { setup_logging(); - if atty::is(atty::Stream::Stdout) { - println!("{}", banner(crate_name!(), crate_version!())); - } + maybe_print_banner(crate_name!(), crate_version!()); let args = Cli::parse(); setup_env(args.config_env_file.as_ref()); diff --git a/nym-wallet/Cargo.lock b/nym-wallet/Cargo.lock index 5b007fc6ff..bcd757d57a 100644 --- a/nym-wallet/Cargo.lock +++ b/nym-wallet/Cargo.lock @@ -2783,6 +2783,7 @@ dependencies = [ name = "nym-bin-common" version = "0.3.0" dependencies = [ + "atty", "clap", "clap_complete", "clap_complete_fig", diff --git a/service-providers/network-requester/src/main.rs b/service-providers/network-requester/src/main.rs index 0629525185..696cb41c21 100644 --- a/service-providers/network-requester/src/main.rs +++ b/service-providers/network-requester/src/main.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use clap::{crate_name, crate_version, Parser}; -use nym_bin_common::logging::{banner, setup_logging}; +use nym_bin_common::logging::{maybe_print_banner, setup_logging}; use nym_network_defaults::setup_env; use error::NetworkRequesterError; @@ -19,7 +19,7 @@ mod statistics; #[tokio::main] async fn main() -> Result<(), NetworkRequesterError> { setup_logging(); - println!("{}", banner(crate_name!(), crate_version!())); + maybe_print_banner(crate_name!(), crate_version!()); let args = cli::Cli::parse(); setup_env(args.config_env_file.as_ref());