style: switch rustfmt to hard tabs; document tests-separate rule in TODO
- rustfmt.toml: hard_tabs = true. - TODO §0.7: tests live in tests/, no #[cfg(test)] modules in code files.
This commit is contained in:
parent
d8393e0f39
commit
a90f0da226
96 changed files with 6542 additions and 6537 deletions
|
|
@ -14,51 +14,51 @@ use rampart::tui::state::AppState;
|
|||
|
||||
#[derive(Parser)]
|
||||
#[command(
|
||||
name = "rampart-tui",
|
||||
about = "Rampart live metrics TUI (Prometheus /metrics source)"
|
||||
name = "rampart-tui",
|
||||
about = "Rampart live metrics TUI (Prometheus /metrics source)"
|
||||
)]
|
||||
struct Cli {
|
||||
/// URL Prometheus metrics endpoint
|
||||
#[arg(long, default_value = "http://127.0.0.1:9090/metrics")]
|
||||
url: String,
|
||||
/// Период опроса, секунды
|
||||
#[arg(long, default_value_t = 1)]
|
||||
refresh_secs: u64,
|
||||
/// URL Prometheus metrics endpoint
|
||||
#[arg(long, default_value = "http://127.0.0.1:9090/metrics")]
|
||||
url: String,
|
||||
/// Период опроса, секунды
|
||||
#[arg(long, default_value_t = 1)]
|
||||
refresh_secs: u64,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
let Some(fetcher) = HttpFetcher::new(cli.url.clone()) else {
|
||||
anyhow::bail!("failed to build http client");
|
||||
};
|
||||
let runtime = tokio::runtime::Builder::new_current_thread().enable_all().build()?;
|
||||
let cli = Cli::parse();
|
||||
let Some(fetcher) = HttpFetcher::new(cli.url.clone()) else {
|
||||
anyhow::bail!("failed to build http client");
|
||||
};
|
||||
let runtime = tokio::runtime::Builder::new_current_thread().enable_all().build()?;
|
||||
|
||||
let terminal = ratatui::try_init()?;
|
||||
let result = runtime.block_on(run(
|
||||
terminal,
|
||||
Arc::new(fetcher) as Arc<dyn Fetcher>,
|
||||
cli.url,
|
||||
Duration::from_secs(cli.refresh_secs.max(1)),
|
||||
));
|
||||
ratatui::restore();
|
||||
result
|
||||
let terminal = ratatui::try_init()?;
|
||||
let result = runtime.block_on(run(
|
||||
terminal,
|
||||
Arc::new(fetcher) as Arc<dyn Fetcher>,
|
||||
cli.url,
|
||||
Duration::from_secs(cli.refresh_secs.max(1)),
|
||||
));
|
||||
ratatui::restore();
|
||||
result
|
||||
}
|
||||
|
||||
async fn run(
|
||||
mut terminal: Terminal<CrosstermBackend<std::io::Stdout>>,
|
||||
fetcher: Arc<dyn Fetcher>,
|
||||
url: String,
|
||||
refresh: Duration,
|
||||
mut terminal: Terminal<CrosstermBackend<std::io::Stdout>>,
|
||||
fetcher: Arc<dyn Fetcher>,
|
||||
url: String,
|
||||
refresh: Duration,
|
||||
) -> anyhow::Result<()> {
|
||||
let state = Arc::new(AppState::new(url));
|
||||
let notify = Arc::new(Notify::new());
|
||||
tokio::spawn(app::spawn_fetch_loop(
|
||||
fetcher,
|
||||
Arc::clone(&state),
|
||||
refresh,
|
||||
Arc::clone(¬ify),
|
||||
));
|
||||
app::run_ui(&mut terminal, state, notify)
|
||||
.await
|
||||
.map_err(anyhow::Error::from)
|
||||
let state = Arc::new(AppState::new(url));
|
||||
let notify = Arc::new(Notify::new());
|
||||
tokio::spawn(app::spawn_fetch_loop(
|
||||
fetcher,
|
||||
Arc::clone(&state),
|
||||
refresh,
|
||||
Arc::clone(¬ify),
|
||||
));
|
||||
app::run_ui(&mut terminal, state, notify)
|
||||
.await
|
||||
.map_err(anyhow::Error::from)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue