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        /// Skip interactive TUI and apply all changes
46        #[arg(short = 'y', long)]
47        yes: bool,
48    },
49}
50
51pub fn run() {
52    run_from(Cli::parse());
53}
54
55pub fn run_from_args<I, T>(args: I)
56where
57    I: IntoIterator<Item = T>,
58    T: Into<OsString> + Clone,
59{
60    run_from(Cli::parse_from(args));
61}
62
63fn run_from(cli: Cli) {
64    let config = load_config();
65
66    match cli.command {
67        Commands::Current => {
68            if let Some(config) = config {
69                if let Some(version) = config.current_version {
70                    println!("{version}");
71                } else {
72                    eprintln!("No current_version found in config");
73                }
74            } else {
75                eprintln!("No config found");
76            }
77        }
78        Commands::Config => {
79            if let Some(config) = config {
80                println!("{}", toml::to_string_pretty(&config).unwrap());
81            } else {
82                eprintln!("No config found");
83            }
84        }
85        Commands::Bump { target, force, yes } => {
86            if let Some(config) = config {
87                if let Err(e) = bump_version(&config, &target, force, yes) {
88                    eprintln!("Error: {e}");
89                }
90            } else {
91                eprintln!("No config found");
92            }
93        }
94    }
95}