gitcc_cli/
init.rs

1//! `init` command
2
3use std::env;
4
5use clap::Parser;
6
7use dialoguer::{theme::ColorfulTheme, Confirm};
8use gitcc_core::Config;
9
10use crate::{error, info, new_line, success, warn};
11
12/// Init command arguments
13#[derive(Debug, Parser)]
14pub struct InitArgs {}
15
16/// Executes the commnad `init`
17pub fn run(_args: InitArgs) -> anyhow::Result<()> {
18    let cwd = env::current_dir()?;
19    let config = Config::load_from_fs(&cwd)?;
20
21    new_line!();
22    if config.is_some() {
23        warn!("repo already has a config");
24        match Confirm::with_theme(&ColorfulTheme::default())
25            .with_prompt("overwrite ?")
26            .report(true)
27            .default(false)
28            .interact()?
29        {
30            false => {
31                error!("config not recreated");
32                return Ok(());
33            }
34            true => {}
35        }
36    } else {
37        info!("config not found");
38    }
39
40    let config = Config::default();
41    config.save_to_fs(&cwd, true)?;
42    success!("created default config");
43    Ok(())
44}