mirror of
https://github.com/0xrsydn/idx-cli.git
synced 2026-08-07 01:33:52 +00:00
style: cargo fmt
This commit is contained in:
parent
5da59c36c7
commit
dc1de5b344
9 changed files with 157 additions and 61 deletions
|
|
@ -3,7 +3,8 @@ use serde::Serialize;
|
|||
use crate::error::IdxError;
|
||||
|
||||
pub fn print_json<T: Serialize + ?Sized>(value: &T) -> Result<(), IdxError> {
|
||||
let out = serde_json::to_string_pretty(value).map_err(|e| IdxError::ParseError(e.to_string()))?;
|
||||
let out =
|
||||
serde_json::to_string_pretty(value).map_err(|e| IdxError::ParseError(e.to_string()))?;
|
||||
println!("{out}");
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,22 @@ pub enum OutputFormat {
|
|||
Json,
|
||||
}
|
||||
|
||||
pub fn render_quotes(quotes: &[Quote], format: &OutputFormat, no_color: bool) -> Result<(), IdxError> {
|
||||
pub fn render_quotes(
|
||||
quotes: &[Quote],
|
||||
format: &OutputFormat,
|
||||
no_color: bool,
|
||||
) -> Result<(), IdxError> {
|
||||
match format {
|
||||
OutputFormat::Table => table::print_quotes(quotes, no_color),
|
||||
OutputFormat::Json => json::print_json(quotes),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_history(symbol: &str, history: &[Ohlc], format: &OutputFormat) -> Result<(), IdxError> {
|
||||
pub fn render_history(
|
||||
symbol: &str,
|
||||
history: &[Ohlc],
|
||||
format: &OutputFormat,
|
||||
) -> Result<(), IdxError> {
|
||||
match format {
|
||||
OutputFormat::Table => table::print_history(symbol, history),
|
||||
OutputFormat::Json => json::print_json(history),
|
||||
|
|
@ -38,7 +46,10 @@ pub fn emit_error(err: &IdxError, format: &OutputFormat) {
|
|||
"code": format!("{:?}", err.code()).to_uppercase(),
|
||||
"message": err.to_string()
|
||||
});
|
||||
eprintln!("{}", serde_json::to_string_pretty(&payload).unwrap_or_else(|_| "{}".to_string()));
|
||||
eprintln!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&payload).unwrap_or_else(|_| "{}".to_string())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use comfy_table::{presets::UTF8_FULL, Cell, Color, ContentArrangement, Table};
|
||||
use comfy_table::{Cell, Color, ContentArrangement, Table, presets::UTF8_FULL};
|
||||
use owo_colors::OwoColorize;
|
||||
|
||||
use crate::api::types::{Ohlc, Quote};
|
||||
|
|
@ -39,7 +39,11 @@ pub fn print_quotes(quotes: &[Quote], no_color: bool) -> Result<(), IdxError> {
|
|||
Cell::new(format!("{:+.2}", q.change)),
|
||||
pct_cell,
|
||||
Cell::new(format_idr(q.volume as f64)),
|
||||
Cell::new(q.market_cap.map(format_idr).unwrap_or_else(|| "-".to_string())),
|
||||
Cell::new(
|
||||
q.market_cap
|
||||
.map(format_idr)
|
||||
.unwrap_or_else(|| "-".to_string()),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue