sheeter-engine 0.2.0

A CLI tool for converting data files between formats. v0.1.0 supports CSV <-> JSON.
Documentation
use clap::{Parser, Subcommand};
use std::fs;
use std::path::PathBuf;

#[derive(Parser)]
#[command(
    name = "sheeter",
    version,
    about = "Convert data files between formats"
)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Convert a CSV file to JSON
    CsvToJson {
        /// Input CSV file
        input: PathBuf,
        /// Output JSON file
        output: PathBuf,
    },
    /// Convert a JSON file to CSV
    JsonToCsv {
        /// Input JSON file
        input: PathBuf,
        /// Output CSV file
        output: PathBuf,
    },
    /// Convert a TSV file to JSON
    TsvToJson {
        /// Input TSV file
        input: PathBuf,
        /// Output JSON file
        output: PathBuf,
    },
    /// Convert a JSON file to TSV
    JsonToTsv {
        /// Input JSON file
        input: PathBuf,
        /// Output TSV file
        output: PathBuf,
    },
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let cli = Cli::parse();
    match cli.command {
        Commands::CsvToJson { input, output } => {
            let csv = fs::read_to_string(input)?;
            let json = sheeter_engine::csv_to_json(&csv)?;
            fs::write(output, json)?;
        }
        Commands::JsonToCsv { input, output } => {
            let json = fs::read_to_string(input)?;
            let csv = sheeter_engine::json_to_csv(&json)?;
            fs::write(output, csv)?;
        }
        Commands::TsvToJson { input, output } => {
            let tsv = fs::read_to_string(input)?;
            let json = sheeter_engine::tsv_to_json(&tsv)?;
            fs::write(output, json)?;
        }
        Commands::JsonToTsv { input, output } => {
            let json = fs::read_to_string(input)?;
            let tsv = sheeter_engine::json_to_tsv(&json)?;
            fs::write(output, tsv)?;
        }
    }
    Ok(())
}