feat(taxonomy): add rust sidecar compact surface pipeline
This commit is contained in:
37
rust/fiscal-xbrl-cli/src/main.rs
Normal file
37
rust/fiscal-xbrl-cli/src/main.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use fiscal_xbrl_core::{hydrate_filing, HydrateFilingRequest};
|
||||
use std::env;
|
||||
use std::io::{self, Read};
|
||||
|
||||
fn main() {
|
||||
if let Err(error) = run() {
|
||||
eprintln!("{error:#}");
|
||||
let code = match error.to_string().as_str() {
|
||||
message if message.contains("invalid request") => 6,
|
||||
message if message.contains("taxonomy resolution") => 4,
|
||||
message if message.contains("parse") => 3,
|
||||
message if message.contains("fetch") || message.contains("request failed") => 2,
|
||||
_ => 5,
|
||||
};
|
||||
std::process::exit(code);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
let command = env::args().nth(1).unwrap_or_default();
|
||||
if command != "hydrate-filing" {
|
||||
return Err(anyhow!("invalid request: expected `hydrate-filing` command"));
|
||||
}
|
||||
|
||||
let mut buffer = String::new();
|
||||
io::stdin()
|
||||
.read_to_string(&mut buffer)
|
||||
.context("invalid request: unable to read stdin")?;
|
||||
|
||||
let request: HydrateFilingRequest = serde_json::from_str(&buffer)
|
||||
.context("invalid request: unable to parse hydrate request JSON")?;
|
||||
|
||||
let response = hydrate_filing(request)?;
|
||||
serde_json::to_writer(io::stdout(), &response).context("unable to write hydrate response")?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user