Skip to main content

_bver/
lib.rs

1pub mod bump;
2pub mod cast;
3pub mod finders;
4pub mod git;
5pub mod loader;
6pub mod schema;
7pub mod tui;
8pub mod version;
9
10#[cfg(feature = "python")]
11mod python;
12
13use std::ffi::OsString;
14
15use bump::bump_version;
16use clap::{Parser, Subcommand};
17use loader::load_config;
18
19#[derive(Parser)]
20#[command(name = "bver")]
21#[command(about = "A version management tool")]
22#[command(version)]
23#[command(arg_required_else_help = true)]
24struct Cli {
25    #[command(subcommand)]
26    command: Commands,
27}
28
29#[derive(Subcommand)]
30enum Commands {
31    /// Show current version
32    Current,
33    /// Show full config
34    Config,
35    /// Bump version
36    Bump {
37        /// Version component (major, minor, patch) or explicit version (e.g. 1.2.3)
38        #[arg(default_value = "patch")]
39        target: String,
40
41        /// Force git operations (tag, push)
42        #[arg(short, long)]
43        force: bool,
44    },
45}
46
47pub fn run() {
48    run_from(Cli::parse());
49}
50
51pub fn run_from_args<I, T>(args: I)
52where
53    I: IntoIterator<Item = T>,
54    T: Into<OsString> + Clone,
55{
56    run_from(Cli::parse_from(args));
57}
58
59fn run_from(cli: Cli) {
60    let config = load_config();
61
62    match cli.command {
63        Commands::Current => {
64            if let Some(config) = config {
65                if let Some(version) = config.current_version {
66                    println!("{version}");
67                } else {
68                    eprintln!("No current_version found in config");
69                }
70            } else {
71                eprintln!("No config found");
72            }
73        }
74        Commands::Config => {
75            if let Some(config) = config {
76                println!("{}", toml::to_string_pretty(&config).unwrap());
77            } else {
78                eprintln!("No config found");
79            }
80        }
81        Commands::Bump { target, force } => {
82            if let Some(config) = config {
83                if let Err(e) = bump_version(&config, &target, force) {
84                    eprintln!("Error: {e}");
85                }
86            } else {
87                eprintln!("No config found");
88            }
89        }
90    }
91}