commit_wizard/lib.rs
1//! # Commit Wizard
2//!
3//! A lightweight Rust library for **Conventional Commits**, semantic versioning, and changelog automation.
4//!
5//! This crate provides the core functionality for validating commits, managing versions, generating
6//! changelogs, and managing Git tags according to semantic versioning principles. It can be used
7//! programmatically via the library interface or through the `cw` CLI binary.
8//!
9//! ## Modules
10//!
11//! - [`cli`]: Command-line interface implementation (public commands and arguments)
12//! - [`core`]: Core application logic including bootstrap, context management, and use cases
13//! - [`engine`]: Business logic layer with traits, models, capabilities, and configuration
14//! - [`infra`]: Infrastructure layer for Git operations, UI interactions, and file system access
15//!
16//! ## Example Usage
17//!
18//! ```ignore
19//! use commit_wizard::core::Context;
20//!
21//! #[tokio::main]
22//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
23//! // Create application context
24//! let context = Context::new().await?;
25//!
26//! // Use context to access capabilities and operations
27//! Ok(())
28//! }
29//! ```
30//!
31//! ## Conventional Commits
32//!
33//! This library enforces [Conventional Commits](https://www.conventionalcommits.org/) format:
34//!
35//! ```text
36//! <type>(<scope>): <description>
37//!
38//! <body>
39//!
40//! <footer>
41//! ```
42//!
43//! Supported types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`, `ci`, `build`
44//!
45//! ## Semantic Versioning
46//!
47//! Version bumping follows [Semantic Versioning](https://semver.org/) principles:
48//! - `MAJOR`: Breaking changes (`feat!` or `BREAKING CHANGE`)
49//! - `MINOR`: New features (`feat`)
50//! - `PATCH`: Bug fixes (`fix`)
51
52pub mod cli;
53pub mod core;
54pub mod engine;
55pub mod infra;
56
57/// A macro to create a vector of strings from a list of string literals.
58#[macro_export]
59macro_rules! strings {
60 ($($s:expr),* $(,)?) => {
61 vec![$($s.to_string()),*]
62 };
63}
64
65#[macro_export]
66macro_rules! string_vec_map {
67 (
68 $(
69 $key:expr => [$($val:expr),* $(,)?]
70 ),* $(,)?
71 ) => {{
72 let mut map = std::collections::BTreeMap::new();
73 $(
74 let vec = vec![$($val.to_string()),*];
75 map.insert($key.to_string(), vec);
76 )*
77 map
78 }};
79}
80
81#[cfg(test)]
82mod tests {
83
84 #[test]
85 fn strings_macro_works_as_expected() {
86 let result = strings!["hello", "world", "123"];
87 let expected = vec!["hello".to_string(), "world".to_string(), "123".to_string()];
88 assert_eq!(result, expected);
89 }
90
91 #[test]
92 fn string_vec_map_macro_works_as_expected() {
93 let result = string_vec_map! {
94 "a" => ["1", "2"],
95 "b" => ["3", "4"]
96 };
97 let mut expected = std::collections::BTreeMap::new();
98 expected.insert("a".to_string(), vec!["1".to_string(), "2".to_string()]);
99 expected.insert("b".to_string(), vec!["3".to_string(), "4".to_string()]);
100 assert_eq!(result, expected);
101 }
102}