sheeter-engine 0.4.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,
    },
    /// 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 },
    /// Convert XML to JSON
    XmlToJson { input: PathBuf, output: PathBuf },
    /// Convert JSON to XML
    JsonToXml { input: PathBuf, output: PathBuf },
    /// Convert CSV to XML
    CsvToXml { input: PathBuf, output: PathBuf },
    /// Convert TSV to XML
    TsvToXml { input: PathBuf, output: PathBuf },
    /// Convert YAML to XML
    YamlToXml { input: PathBuf, output: PathBuf },
    /// Convert XML to CSV
    XmlToCsv { input: PathBuf, output: PathBuf },
    /// Convert XML to TSV
    XmlToTsv { input: PathBuf, output: PathBuf },
    /// Convert XML to YAML
    XmlToYaml { input: PathBuf, output: PathBuf },
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let cli = Cli::parse();
    match cli.command {
        Commands::CsvToJson { input, output } => {
            fs::write(
                output,
                sheeter_engine::csv_to_json(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::JsonToCsv { input, output } => {
            fs::write(
                output,
                sheeter_engine::json_to_csv(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::TsvToJson { input, output } => {
            fs::write(
                output,
                sheeter_engine::tsv_to_json(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::JsonToTsv { input, output } => {
            fs::write(
                output,
                sheeter_engine::json_to_tsv(&fs::read_to_string(input)?)?,
            )?;
        }
        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)?)?,
            )?;
        }
        Commands::XmlToJson { input, output } => {
            fs::write(
                output,
                sheeter_engine::xml_to_json(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::JsonToXml { input, output } => {
            fs::write(
                output,
                sheeter_engine::json_to_xml(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::CsvToXml { input, output } => {
            fs::write(
                output,
                sheeter_engine::csv_to_xml(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::TsvToXml { input, output } => {
            fs::write(
                output,
                sheeter_engine::tsv_to_xml(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::YamlToXml { input, output } => {
            fs::write(
                output,
                sheeter_engine::yaml_to_xml(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::XmlToCsv { input, output } => {
            fs::write(
                output,
                sheeter_engine::xml_to_csv(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::XmlToTsv { input, output } => {
            fs::write(
                output,
                sheeter_engine::xml_to_tsv(&fs::read_to_string(input)?)?,
            )?;
        }
        Commands::XmlToYaml { input, output } => {
            fs::write(
                output,
                sheeter_engine::xml_to_yaml(&fs::read_to_string(input)?)?,
            )?;
        }
    }
    Ok(())
}