gitcc_cli/
version.rs

1//! `version` command
2
3use std::env;
4
5use clap::Parser;
6use gitcc_core::{commit_history, Config, StatusShow};
7
8use crate::{info, new_line, warn};
9
10/// Bump command arguments
11#[derive(Debug, Parser)]
12pub struct VersionArgs {}
13
14/// Gets the current version and determines the next version
15pub fn run(_args: VersionArgs) -> anyhow::Result<()> {
16    new_line!();
17
18    // load the config
19    let cwd = env::current_dir().unwrap();
20    let config = Config::load_from_fs(&cwd)?;
21    let config = if let Some(cfg) = config {
22        cfg
23    } else {
24        info!("using default config");
25        Config::default()
26    };
27
28    // Checks that the repo is clean
29    let status = gitcc_core::git_status(&cwd, StatusShow::IndexAndWorkdir)?;
30    if !status.is_empty() {
31        warn!("repo is dirty");
32    }
33
34    let history = commit_history(&cwd, &config)?;
35    println!(
36        "{} --> {}",
37        history
38            .curr_version
39            .map(|v| v.to_string())
40            .unwrap_or_else(|| "none".to_string()),
41        history.next_version
42    );
43
44    Ok(())
45}