gitbackup 0.2.6

Backup all your git repositories with a single command
use crate::types::{AppConfig, EnabledProvider, Provider};
use anyhow::Result;

pub fn init() -> Result<()> {
    let path = AppConfig::get_config_path()?;

    if path.exists() {
        return Err(anyhow::anyhow!(
            "Config file already exists at {}",
            path.display()
        ));
    }

    let config = AppConfig {
        backup_path: String::from("gitarchive"),
        providers: vec![
            Provider {
                provider: EnabledProvider::GitHub,
                host: String::from("github.com"),
                exclude: vec![String::from("facebook/react")],
                username: String::from("MY_USERNAME"),
                token: String::from("MY_GITHUB_TOKEN"),
            },
            Provider {
                provider: EnabledProvider::GitLab,
                host: String::from("gitlab.com"),
                exclude: vec![],
                username: String::from("MY_USERNAME"),
                token: String::from("MY_GITLAB_TOKEN"),
            },
            Provider {
                provider: EnabledProvider::Forgejo,
                host: String::from("codeberg.org"),
                exclude: vec![],
                username: String::from("MY_USERNAME"),
                token: String::from("MY_FORGEJO_TOKEN"),
            },
        ],
    };

    AppConfig::set_config_file(&toml::to_string(&config)?)?;

    println!("Config file successfully initialized at {}", path.display());

    Ok(())
}