use crate::spawn::ensure_daemon_safe;
use clap::Subcommand;
use night_fury_daemon_core::cli::make_req;
use night_fury_daemon_core::client;
use serde_json::json;
use super::{acquire_then_exec, ExecArgs};
#[derive(Subcommand)]
pub enum BloombergCmd {
Section {
section: String,
#[arg(long, default_value_t = 10)]
limit: u64,
#[arg(long, default_value_t = 0)]
offset: u64,
},
Article { story_id: String },
SectionFull {
section: String,
#[arg(long, default_value_t = 5)]
limit: u64,
#[arg(long, default_value_t = 0)]
offset: u64,
},
}
pub async fn run(
cmd: BloombergCmd,
socket: &str,
host: &str,
session: Option<String>,
) -> anyhow::Result<()> {
let (cmd_name, params) = match cmd {
BloombergCmd::Section {
section,
limit,
offset,
} => (
"bloomberg.section",
json!({"section": section, "limit": limit, "offset": offset}),
),
BloombergCmd::Article { story_id } => ("bloomberg.article", json!({"story_id": story_id})),
BloombergCmd::SectionFull {
section,
limit,
offset,
} => (
"bloomberg.section-full",
json!({"section": section, "limit": limit, "offset": offset}),
),
};
if let Some(sid) = session {
ensure_daemon_safe(socket).await?;
let req = make_req(cmd_name, Some(&sid), params);
let resp = client::send(socket, &req).await?;
super::print_and_check(&resp);
return Ok(());
}
let args = ExecArgs {
site: "bloomberg",
host,
cmd: cmd_name,
params,
};
acquire_then_exec(socket, args).await
}