sheeter-engine 0.3.1

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,
    },
    /// Convert CSV to YAML
    CsvToYaml { input: PathBuf, output: PathBuf },
    /// Convert TSV to YAML
    TsvToYaml { input: PathBuf, output: PathBuf },
    /// Convert JSON to YAML
    JsonToYaml { input: PathBuf, output: PathBuf },
    /// Convert YAML to CSV
    YamlToCsv { input: PathBuf, output: PathBuf },
    /// Convert YAML to TSV
    YamlToTsv { input: PathBuf, output: PathBuf },
    /// Convert YAML to JSON
    YamlToJson { input: PathBuf, output: PathBuf },
    /// Convert CSV to TSV
    CsvToTsv { input: PathBuf, output: PathBuf },
    /// Convert TSV to CSV
    TsvToCsv { input: PathBuf, 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)?;
        }
        Commands::CsvToYaml { input, output } => {
            fs::write(
                output,
                sheeter_engine::csv_to_yaml(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::TsvToYaml { input, output } => {
            fs::write(
                output,
                sheeter_engine::tsv_to_yaml(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::JsonToYaml { input, output } => {
            fs::write(
                output,
                sheeter_engine::json_to_yaml(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::YamlToCsv { input, output } => {
            fs::write(
                output,
                sheeter_engine::yaml_to_csv(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::YamlToTsv { input, output } => {
            fs::write(
                output,
                sheeter_engine::yaml_to_tsv(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::YamlToJson { input, output } => {
            fs::write(
                output,
                sheeter_engine::yaml_to_json(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::CsvToTsv { input, output } => {
            fs::write(
                output,
                sheeter_engine::csv_to_tsv(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::TsvToCsv { input, output } => {
            fs::write(
                output,
                sheeter_engine::tsv_to_csv(&fs::read_to_string(input)?)?,
            )?;
        }
    }
    Ok(())
}