style: cargo fmt

This commit is contained in:
Ciphercat 2026-03-05 18:33:20 +00:00
commit dc1de5b344
9 changed files with 157 additions and 61 deletions

View file

@ -1,7 +1,7 @@
use clap::{Args, Subcommand};
use crate::api::types::{Interval, Period};
use crate::api::MarketDataProvider;
use crate::api::types::{Interval, Period};
use crate::cache::Cache;
use crate::config::IdxConfig;
use crate::error::IdxError;
@ -15,7 +15,9 @@ pub struct StocksCmd {
#[derive(Debug, Subcommand)]
pub enum StocksSubcommand {
Quote { symbols: Vec<String> },
Quote {
symbols: Vec<String>,
},
History {
symbol: String,
#[arg(long, value_enum, default_value_t = Period::ThreeMonths)]
@ -39,9 +41,7 @@ pub fn handle(
let mut quotes = Vec::new();
for sym in symbols.iter().flat_map(|s| s.split(',')) {
let resolved = crate::api::resolve_symbol(sym, &config.exchange);
if !no_cache
&& let Some(q) = cache.get("quote", &resolved)?
{
if !no_cache && let Some(q) = cache.get("quote", &resolved)? {
quotes.push(q);
continue;
}
@ -61,10 +61,10 @@ pub fn handle(
quotes.push(q);
}
Err(err) => {
if !no_cache
&& let Some(stale) = cache.get_stale("quote", &resolved)?
{
eprintln!("warning: network failed, serving stale cache for {resolved}");
if !no_cache && let Some(stale) = cache.get_stale("quote", &resolved)? {
eprintln!(
"warning: network failed, serving stale cache for {resolved}"
);
quotes.push(stale);
continue;
}
@ -82,13 +82,17 @@ pub fn handle(
let resolved = crate::api::resolve_symbol(symbol, &config.exchange);
let key = format!("{}-{}", period.as_str(), interval.as_str());
if !no_cache
&& let Some(history) = cache.get::<Vec<crate::api::types::Ohlc>>("history", &format!("{resolved}-{key}"))?
&& let Some(history) = cache
.get::<Vec<crate::api::types::Ohlc>>("history", &format!("{resolved}-{key}"))?
{
return render_history(&resolved, &history, &config.output);
}
if offline {
let stale = cache
.get_stale::<Vec<crate::api::types::Ohlc>>("history", &format!("{resolved}-{key}"))?
.get_stale::<Vec<crate::api::types::Ohlc>>(
"history",
&format!("{resolved}-{key}"),
)?
.ok_or_else(|| IdxError::CacheMiss(format!("history/{resolved}-{key}")))?;
return render_history(&resolved, &stale, &config.output);
}
@ -96,13 +100,21 @@ pub fn handle(
match provider.history(&resolved, period, interval) {
Ok(history) => {
if !no_cache {
cache.put("history", &format!("{resolved}-{key}"), &history, config.quote_ttl)?;
cache.put(
"history",
&format!("{resolved}-{key}"),
&history,
config.quote_ttl,
)?;
}
render_history(&resolved, &history, &config.output)
}
Err(err) => {
if !no_cache
&& let Some(stale) = cache.get_stale::<Vec<crate::api::types::Ohlc>>("history", &format!("{resolved}-{key}"))?
&& let Some(stale) = cache.get_stale::<Vec<crate::api::types::Ohlc>>(
"history",
&format!("{resolved}-{key}"),
)?
{
eprintln!("warning: network failed, serving stale cache for {resolved}");
return render_history(&resolved, &stale, &config.output);