standarise printing of banner based on tty

This commit is contained in:
Jędrzej Stuczyński
2023-04-04 10:00:29 +01:00
parent 3b8dd1f4a5
commit 01aa06e488
10 changed files with 21 additions and 18 deletions
Generated
+1 -1
View File
@@ -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",
+2 -2
View File
@@ -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<dyn Error + Send + Sync>> {
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());
+2 -2
View File
@@ -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<dyn Error + Send + Sync>> {
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());
+1
View File
@@ -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"
+6
View File
@@ -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))
}
}
+3 -5
View File
@@ -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<dyn Error + Send + Sync>> {
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());
-1
View File
@@ -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" }
+3 -5
View File
@@ -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());
+1
View File
@@ -2783,6 +2783,7 @@ dependencies = [
name = "nym-bin-common"
version = "0.3.0"
dependencies = [
"atty",
"clap",
"clap_complete",
"clap_complete_fig",
@@ -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());