common: dedup and move banner to common/logging (#2846)

This commit is contained in:
Jon Häggblad
2023-01-16 08:32:35 +01:00
committed by GitHub
parent cc7161c113
commit dc71f6e94d
6 changed files with 26 additions and 77 deletions
+2 -19
View File
@@ -3,7 +3,7 @@
use std::error::Error;
use clap::{crate_version, Parser};
use clap::{crate_name, crate_version, Parser};
use logging::setup_logging;
use network_defaults::setup_env;
@@ -15,26 +15,9 @@ pub mod websocket;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
setup_logging();
println!("{}", banner());
println!("{}", logging::banner(crate_name!(), crate_version!()));
let args = commands::Cli::parse();
setup_env(args.config_env_file.as_ref());
commands::execute(&args).await
}
fn banner() -> String {
format!(
r#"
_ __ _ _ _ __ ___
| '_ \| | | | '_ \ _ \
| | | | |_| | | | | | |
|_| |_|\__, |_| |_| |_|
|___/
(client - version {:})
"#,
crate_version!()
)
}
+2 -19
View File
@@ -3,7 +3,7 @@
use std::error::Error;
use clap::{crate_version, Parser};
use clap::{crate_name, crate_version, Parser};
use logging::setup_logging;
use network_defaults::setup_env;
@@ -15,26 +15,9 @@ pub mod socks;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
setup_logging();
println!("{}", banner());
println!("{}", logging::banner(crate_name!(), crate_version!()));
let args = commands::Cli::parse();
setup_env(args.config_env_file.as_ref());
commands::execute(&args).await
}
fn banner() -> String {
format!(
r#"
_ __ _ _ _ __ ___
| '_ \| | | | '_ \ _ \
| | | | |_| | | | | | |
|_| |_|\__, |_| |_| |_|
|___/
(socks5 proxy - version {:})
"#,
crate_version!()
)
}
+1 -1
View File
@@ -7,4 +7,4 @@ edition = "2021"
[dependencies]
log = "0.4.0"
pretty_env_logger = "0.4.0"
pretty_env_logger = "0.4.0"
+17
View File
@@ -23,3 +23,20 @@ pub fn setup_logging() {
.filter_module("sled", log::LevelFilter::Warn)
.init();
}
pub fn banner(crate_name: &str, crate_version: &str) -> String {
format!(
r#"
_ __ _ _ _ __ ___
| '_ \| | | | '_ \ _ \
| | | | |_| | | | | | |
|_| |_|\__, |_| |_| |_|
|___/
({:} - version {:})
"#,
crate_name, crate_version
)
}
+2 -19
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use build_information::BinaryBuildInformation;
use clap::{crate_version, Parser, ValueEnum};
use clap::{crate_name, crate_version, Parser, ValueEnum};
use colored::Colorize;
use lazy_static::lazy_static;
use log::error;
@@ -66,7 +66,7 @@ impl Cli {
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
setup_logging();
if atty::is(atty::Stream::Stdout) {
println!("{}", banner());
println!("{}", logging::banner(crate_name!(), crate_version!()));
}
let args = Cli::parse();
@@ -82,23 +82,6 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
})
}
fn banner() -> String {
format!(
r#"
_ __ _ _ _ __ ___
| '_ \| | | | '_ \ _ \
| | | | |_| | | | | | |
|_| |_|\__, |_| |_| |_|
|___/
(gateway - version {:})
"#,
crate_version!()
)
}
#[cfg(test)]
mod tests {
use super::*;
+2 -19
View File
@@ -6,7 +6,7 @@ extern crate rocket;
use ::config::defaults::setup_env;
use build_information::BinaryBuildInformation;
use clap::{crate_version, Parser, ValueEnum};
use clap::{crate_name, crate_version, Parser, ValueEnum};
use lazy_static::lazy_static;
use logging::setup_logging;
@@ -64,7 +64,7 @@ impl Cli {
async fn main() {
setup_logging();
if atty::is(atty::Stream::Stdout) {
println!("{}", banner());
println!("{}", logging::banner(crate_name!(), crate_version!()));
}
let args = Cli::parse();
@@ -72,23 +72,6 @@ async fn main() {
commands::execute(args).await;
}
fn banner() -> String {
format!(
r#"
_ __ _ _ _ __ ___
| '_ \| | | | '_ \ _ \
| | | | |_| | | | | | |
|_| |_|\__, |_| |_| |_|
|___/
(mixnode - version {:})
"#,
crate_version!()
)
}
#[cfg(test)]
mod tests {
use super::*;