commit_wizard/lib.rs
1#![doc = include_str!("../README.md")]
2//!
3//! ---
4//!
5//! ## This is a tool, not a library
6//!
7//! The code is published as a library crate only so that the `cw` binary, its tests and
8//! docs.rs can share it. Everything except [`cli::run`] is hidden from these docs and carries
9//! **no stability guarantee**: it may change in any release, patch releases included. If you
10//! want to build on `cw`, depend on its command line and its configuration files, not on this
11//! API.
12//!
13//! ## Contributing to the code
14//!
15//! The crate is layered from the outside in: `cli` (argument parsing and dispatch), `core`
16//! (the use case behind each command), `engine` (models, configuration and rules, with no I/O)
17//! and `infra` (Git, terminal and file-system adapters).
18//! [ARCHITECTURE.md](https://github.com/KiTechSoftware/commit-wizard/blob/main/ARCHITECTURE.md)
19//! walks through how a command flows through them and how to add one, and
20//! `cargo doc --document-private-items --open` shows the hidden modules.
21//!
22//! ## What `cw` enforces
23//!
24//! Commits follow the Conventional Commits layout:
25//!
26//! ```text
27//! <type>(<scope>): <description>
28//!
29//! <body>
30//!
31//! <footer>
32//! ```
33//!
34//! The allowed types and scopes come from your configuration (the standard profile ships
35//! `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test` and `chore`; a shared registry or
36//! your own config can add more). Version bumps follow [Semantic Versioning](https://semver.org/):
37//!
38//! - **major**: a breaking change (`feat!:` or a `BREAKING CHANGE:` footer)
39//! - **minor**: a new feature (`feat`)
40//! - **patch**: a fix (`fix`) and other patch-level types
41
42#![warn(missing_docs)]
43
44pub mod cli;
45
46// Implementation detail: hidden from the API docs and not covered by any stability promise.
47#[doc(hidden)]
48pub mod core;
49#[doc(hidden)]
50pub mod engine;
51#[doc(hidden)]
52pub mod infra;
53
54/// A macro to create a vector of strings from a list of string literals.
55#[doc(hidden)]
56#[macro_export]
57macro_rules! strings {
58 ($($s:expr),* $(,)?) => {
59 vec![$($s.to_string()),*]
60 };
61}
62
63#[doc(hidden)]
64#[macro_export]
65macro_rules! string_vec_map {
66 (
67 $(
68 $key:expr => [$($val:expr),* $(,)?]
69 ),* $(,)?
70 ) => {{
71 let mut map = std::collections::BTreeMap::new();
72 $(
73 let vec = vec![$($val.to_string()),*];
74 map.insert($key.to_string(), vec);
75 )*
76 map
77 }};
78}
79
80#[cfg(test)]
81mod tests {
82
83 #[test]
84 fn strings_macro_works_as_expected() {
85 let result = strings!["hello", "world", "123"];
86 let expected = vec!["hello".to_string(), "world".to_string(), "123".to_string()];
87 assert_eq!(result, expected);
88 }
89
90 #[test]
91 fn string_vec_map_macro_works_as_expected() {
92 let result = string_vec_map! {
93 "a" => ["1", "2"],
94 "b" => ["3", "4"]
95 };
96 let mut expected = std::collections::BTreeMap::new();
97 expected.insert("a".to_string(), vec!["1".to_string(), "2".to_string()]);
98 expected.insert("b".to_string(), vec!["3".to_string(), "4".to_string()]);
99 assert_eq!(result, expected);
100 }
101}