1use jsona_util::{environment::Environment, schema::Schemas};
2use url::Url;
3
4pub use crate::commands::{AppArgs, Colors, GeneralArgs};
5
6use anyhow::anyhow;
7pub mod commands;
8pub mod printing;
9
10pub struct App<E: Environment> {
11 env: E,
12 colors: bool,
13 schemas: Schemas<E>,
14}
15
16impl<E: Environment> App<E> {
17 pub fn new(env: E) -> Self {
18 Self {
19 schemas: Schemas::new(env.clone()),
20 colors: env.atty_stderr(),
21 env,
22 }
23 }
24 pub async fn load_file(&self, path: &str) -> Result<(Url, String), anyhow::Error> {
25 let url = self
26 .env
27 .to_url(path)
28 .ok_or_else(|| anyhow!("invalid file path"))?;
29 let data = self.env.read_file(&url).await?;
30 let content = std::str::from_utf8(&data).map_err(|_| anyhow!("invalid utf8 content"))?;
31 Ok((url, content.to_string()))
32 }
33}