Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyigumnov committed Mar 28, 2024
1 parent a8e7f3c commit 27f54a3
Show file tree
Hide file tree
Showing 6 changed files with 659 additions and 430 deletions.
53 changes: 16 additions & 37 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::collections::HashMap;
use bytes::Bytes;
use clap::{Parser, ValueEnum};
use shiva::core::TransformerTrait;

use std::collections::HashMap;

#[derive(Parser, Debug)]
#[command(name="shiva", author, version, about, long_about = None)]
struct Args {

#[arg(long)]
input_file: Option<String>,

Expand All @@ -19,9 +17,6 @@ struct Args {

#[arg(long)]
output_format: InputFormat,



}

#[derive(Debug, Parser, Clone, ValueEnum)]
Expand All @@ -32,50 +27,34 @@ enum InputFormat {
Pdf,
}
fn main() -> anyhow::Result<()> {


let args = Args::parse();

let input_vec = std::fs::read(args.input_file.ok_or(anyhow::anyhow!("No input file provided"))?)?;
let input_vec = std::fs::read(
args.input_file
.ok_or(anyhow::anyhow!("No input file provided"))?,
)?;
let input_bytes = Bytes::from(input_vec);


let document = match args.input_format {
InputFormat::Markdown => {
shiva::markdown::Transformer::parse(&input_bytes, &HashMap::new())?
}
InputFormat::Html => {
shiva::html::Transformer::parse(&input_bytes, &HashMap::new())?
}
InputFormat::Text => {
shiva::text::Transformer::parse(&input_bytes, &HashMap::new())?
}
InputFormat::Pdf => {
shiva::pdf::Transformer::parse(&input_bytes, &HashMap::new())?
}
InputFormat::Html => shiva::html::Transformer::parse(&input_bytes, &HashMap::new())?,
InputFormat::Text => shiva::text::Transformer::parse(&input_bytes, &HashMap::new())?,
InputFormat::Pdf => shiva::pdf::Transformer::parse(&input_bytes, &HashMap::new())?,
};


let output = match args.output_format {
InputFormat::Text => {
shiva::text::Transformer::generate(&document)?
}
InputFormat::Html => {
shiva::html::Transformer::generate(&document)?
}
InputFormat::Markdown => {
shiva::markdown::Transformer::generate(&document)?
}
InputFormat::Pdf => {
shiva::pdf::Transformer::generate(&document)?
}

InputFormat::Text => shiva::text::Transformer::generate(&document)?,
InputFormat::Html => shiva::html::Transformer::generate(&document)?,
InputFormat::Markdown => shiva::markdown::Transformer::generate(&document)?,
InputFormat::Pdf => shiva::pdf::Transformer::generate(&document)?,
};

let file_name = args.output_file.ok_or(anyhow::anyhow!("No output file provided"))?;
let file_name = args
.output_file
.ok_or(anyhow::anyhow!("No output file provided"))?;
std::fs::write(file_name, output.0)?;

Ok(())


}
}
Loading

0 comments on commit 27f54a3

Please sign in to comment.