trixy 0.4.0

A rust crate used to generate multi-language apis for your application
Documentation
/*
* Copyright (C) 2023 - 2024:
* The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This file is part of the Trixy crate for Trinitrix.
*
* Trixy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

use std::path::Path;

use trixy::macros::config::trixy::TrixyConfig;

use crate::cli::{GenCommand, Language};

pub fn handle(
    gen_command: GenCommand,
    // TODO: Add support for the language argument <2024-07-25>
    _language: Language,
    api_file: &Path,
    write_files: bool,
    vendored: bool,
) -> anyhow::Result<()> {
    let base_config = TrixyConfig::new("callback_function")
        .trixy_path(api_file.to_owned())
        .dist_dir_path("include")
        .out_dir_path("");

    let final_config: TrixyConfig;
    match gen_command {
        GenCommand::Host => {
            final_config = base_config
                .generate_auxiliary(false)
                .generate_host(true)
                .add_c_headers(vendored);
        }
        GenCommand::Auxiliary => {
            final_config = base_config
                .generate_auxiliary(true)
                .generate_host(false)
                .add_c_headers(vendored);
        }
        GenCommand::All {} => {
            final_config = base_config
                .generate_auxiliary(true)
                .generate_host(true)
                .add_c_headers(vendored);
        }
    }

    let file_tree = final_config.generate();

    if write_files {
        file_tree.materialize()?;
    } else {
        println!("{}", file_tree);
    }

    Ok(())
}