Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Trace configuration for loading wait indicators and --teach-me flag moved to library #417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,57 @@ pub struct GlobalContext {
pub offline: bool,
pub teach_me: bool,
}

pub fn setup_tracing(teach_me_flag_is_set: bool) -> CliResult {
use indicatif::ProgressStyle;
use tracing_indicatif::IndicatifLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

if teach_me_flag_is_set {
let env_filter = EnvFilter::from_default_env()
.add_directive(tracing::Level::WARN.into())
.add_directive("near_teach_me=info".parse()?)
.add_directive("near_cli_rs=info".parse()?);
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.without_time()
.with_target(false),
)
.with(env_filter)
.init();
} else {
let indicatif_layer = IndicatifLayer::new()
.with_progress_style(
ProgressStyle::with_template(
"{spinner:.blue}{span_child_prefix} {span_name} {msg} {span_fields}",
)
.unwrap()
.tick_strings(&[
"▹▹▹▹▹",
"▸▹▹▹▹",
"▹▸▹▹▹",
"▹▹▸▹▹",
"▹▹▹▸▹",
"▹▹▹▹▸",
"▪▪▪▪▪",
]),
)
.with_span_child_prefix_symbol("↳ ");
let env_filter = EnvFilter::from_default_env()
.add_directive(tracing::Level::WARN.into())
.add_directive("near_cli_rs=info".parse()?);
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.without_time()
.with_writer(indicatif_layer.get_stderr_writer()),
)
.with(indicatif_layer)
.with(env_filter)
.init();
};
Ok(())
}
52 changes: 1 addition & 51 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ use color_eyre::eyre::WrapErr;
use color_eyre::owo_colors::OwoColorize;
use interactive_clap::ToCliArgs;

use indicatif::ProgressStyle;
use tracing_indicatif::IndicatifLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

pub use near_cli_rs::commands;
pub use near_cli_rs::common::{self, CliResult};
pub use near_cli_rs::config;
Expand All @@ -25,7 +19,6 @@ pub use near_cli_rs::network_view_at_block;
pub use near_cli_rs::transaction_signature_options;
pub use near_cli_rs::types;
pub use near_cli_rs::utils_command;

pub use near_cli_rs::GlobalContext;

type ConfigContext = (crate::config::Config,);
Expand Down Expand Up @@ -120,50 +113,7 @@ fn main() -> crate::common::CliResult {
}
},
};
if cli.teach_me {
let env_filter = EnvFilter::from_default_env()
.add_directive(tracing::Level::WARN.into())
.add_directive("near_teach_me=info".parse()?)
.add_directive("near_cli_rs=info".parse()?);
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.without_time()
.with_target(false),
)
.with(env_filter)
.init();
} else {
let indicatif_layer = IndicatifLayer::new()
.with_progress_style(
ProgressStyle::with_template(
"{spinner:.blue}{span_child_prefix} {span_name} {msg} {span_fields}",
)
.unwrap()
.tick_strings(&[
"▹▹▹▹▹",
"▸▹▹▹▹",
"▹▸▹▹▹",
"▹▹▸▹▹",
"▹▹▹▸▹",
"▹▹▹▹▸",
"▪▪▪▪▪",
]),
)
.with_span_child_prefix_symbol("↳ ");
let env_filter = EnvFilter::from_default_env()
.add_directive(tracing::Level::WARN.into())
.add_directive("near_cli_rs=info".parse()?);
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.without_time()
.with_writer(indicatif_layer.get_stderr_writer()),
)
.with(indicatif_layer)
.with(env_filter)
.init();
};
near_cli_rs::setup_tracing(cli.teach_me)?;

let cli_cmd = match <Cmd as interactive_clap::FromCli>::from_cli(Some(cli), (config,)) {
interactive_clap::ResultFromCli::Ok(cli_cmd)
Expand Down
Loading