soroban_cli/commands/
global.rs

1use clap::{
2    arg,
3    builder::styling::{AnsiColor, Effects, Styles},
4};
5use std::path::PathBuf;
6
7use super::{config, HEADING_GLOBAL};
8
9const USAGE_STYLES: Styles = Styles::styled()
10    .header(AnsiColor::Green.on_default().effects(Effects::BOLD))
11    .usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
12    .literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
13    .placeholder(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
14    .error(AnsiColor::Red.on_default().effects(Effects::BOLD))
15    .valid(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
16    .invalid(AnsiColor::Yellow.on_default().effects(Effects::BOLD));
17
18#[derive(Debug, clap::Args, Clone, Default)]
19#[group(skip)]
20#[allow(clippy::struct_excessive_bools)]
21#[command(styles = USAGE_STYLES)]
22pub struct Args {
23    #[clap(flatten)]
24    pub locator: config::locator::Args,
25
26    /// Filter logs output. To turn on `stellar_cli::log::footprint=debug` or off `=off`. Can also use env var `RUST_LOG`.
27    #[arg(long, short = 'f', global = true, help_heading = HEADING_GLOBAL)]
28    pub filter_logs: Vec<String>,
29
30    /// Do not write logs to stderr including `INFO`
31    #[arg(long, short = 'q', global = true, help_heading = HEADING_GLOBAL)]
32    pub quiet: bool,
33
34    /// Log DEBUG events
35    #[arg(long, short = 'v', global = true, help_heading = HEADING_GLOBAL)]
36    pub verbose: bool,
37
38    /// Log DEBUG and TRACE events
39    #[arg(long, visible_alias = "vv", global = true, help_heading = HEADING_GLOBAL)]
40    pub very_verbose: bool,
41
42    /// ⚠️ Deprecated, use `stellar plugin ls`. List installed plugins. E.g. `stellar-hello`
43    #[arg(long)]
44    pub list: bool,
45
46    /// Do not cache your simulations and transactions
47    #[arg(long, env = "STELLAR_NO_CACHE", global = true, help_heading = HEADING_GLOBAL)]
48    pub no_cache: bool,
49}
50
51#[derive(thiserror::Error, Debug)]
52pub enum Error {
53    #[error("reading file {filepath}: {error}")]
54    CannotReadLedgerFile {
55        filepath: PathBuf,
56        error: soroban_ledger_snapshot::Error,
57    },
58
59    #[error("committing file {filepath}: {error}")]
60    CannotCommitLedgerFile {
61        filepath: PathBuf,
62        error: soroban_ledger_snapshot::Error,
63    },
64}
65
66impl Args {
67    pub fn log_level(&self) -> Option<tracing::Level> {
68        if self.quiet {
69            None
70        } else if self.very_verbose {
71            Some(tracing::Level::TRACE)
72        } else if self.verbose {
73            Some(tracing::Level::DEBUG)
74        } else {
75            Some(tracing::Level::INFO)
76        }
77    }
78}