gtl 0.5.16

gtl is a Git-based tool designed to simplify the management of multiple remote repositories. It extends Git's functionality by providing one-click initialization and pushing to multiple remote repositories, making it especially useful for developers who need to maintain multiple remote repositories simultaneously.
use crate::*;

/// Reads configuration from a file, creates default if not exists.
///
/// # Arguments
///
/// - `P: AsRef<Path>` - The path to the configuration file.
///
/// # Returns
///
/// - `Config` - The parsed configuration.
pub(crate) fn read_config<P: AsRef<Path>>(path: P) -> Config {
    let path_ref: &Path = path.as_ref();
    if !path_ref.exists() {
        if let Some(parent) = path_ref.parent() {
            fs::create_dir_all(parent).expect("Unable to create directories");
        }
        let empty_config: Config = HashMap::new();
        let data: String =
            serde_json::to_string(&empty_config).expect("Unable to serialize empty config");
        fs::write(&path, data).expect("Unable to write empty config file");
    }
    let data: String = fs::read_to_string(path).expect("Unable to read config file");
    serde_json::from_str(&data).expect("Unable to parse config file")
}

/// Gets the package name.
///
/// # Returns
///
/// - `&'static str` - The package name.
pub(crate) fn get_package_name() -> &'static str {
    PACKAGE_NAME
}

/// Gets the package version.
///
/// # Returns
///
/// - `&'static str` - The package version.
pub(crate) fn get_package_version() -> &'static str {
    PACKAGE_VERSION
}