1- use crate :: {
2- config:: { cli:: SimpleCommitsConfig , get_config} ,
3- errors:: AppError ,
4- } ;
1+ use crate :: config:: get_config;
52
63pub mod config_prompt;
74pub mod helpers;
@@ -11,13 +8,13 @@ pub mod widgets;
118
129/// initialize the configuration and setup the steps
1310pub fn init ( ) {
14- let ( mut config, command) = get_config ( ) ;
11+ let ( config, command) = get_config ( ) ;
1512 match command {
1613 Some ( _) => {
17- _ = config_prompt:: init ( & mut config) ;
14+ _ = config_prompt:: init ( config) ;
1815 }
1916 None => {
20- _ = steps:: init ( & mut config) ;
17+ _ = steps:: init ( config) ;
2118 }
2219 }
2320}
@@ -27,65 +24,16 @@ pub struct AppData {
2724 pub commit : CommitBuilder ,
2825}
2926
30- #[ allow( dead_code) ]
31- #[ derive( Clone , Debug , Default ) ]
32- pub enum Action {
33- #[ default]
34- None ,
35- DryRun ( String ) ,
36- Commit ( String , Vec < String > ) ,
37- }
38-
39- impl Action {
40- /// Returns the action to be executed of this [`Action`].
41- pub fn execute_action ( & self ) {
42- match self {
43- Self :: DryRun ( msg) => println ! ( "{msg}" ) ,
44- Self :: Commit ( cmd, args) => {
45- let _ = std:: process:: Command :: new ( cmd)
46- . args ( & args[ ..] )
47- . spawn ( )
48- . expect ( "The child failed for some reason" )
49- . wait ( ) ;
50- }
51- Self :: None => { }
52- }
53- }
54- }
55-
56- pub type StepResult = Result < ( ) , AppError > ;
57-
58- /// A trait to setup steps along the TUI app.
59- pub trait Step {
60- fn before_run (
61- & mut self ,
62- _state : & mut AppData ,
63- _config : & mut SimpleCommitsConfig ,
64- ) -> StepResult {
65- Ok ( ( ) )
66- }
67-
68- fn after_run ( & mut self , _state : & mut AppData , _config : & mut SimpleCommitsConfig ) -> StepResult {
69- Ok ( ( ) )
70- }
71-
72- fn run ( & mut self , state : & mut AppData , config : & mut SimpleCommitsConfig ) -> StepResult ;
73- }
74-
75- #[ macro_export]
76- macro_rules! gen_steps {
77- ( $( $struct: ty) ,* ) => {
78- {
79- let steps: Vec <Box <dyn super :: Step >> = vec![
80- $(
81- Box :: new( <$struct>:: default ( ) ) ,
82- ) *
83- ] ;
84- steps
85- }
86- } ;
87- }
88-
27+ /// Builder for constructing a conventional commit message.
28+ ///
29+ /// This builder follows the Conventional Commits specification and supports:
30+ /// - Commit type (feat, fix, docs, etc.)
31+ /// - Optional scope
32+ /// - Optional emoji
33+ /// - Title/subject line
34+ /// - Optional body/description
35+ /// - Optional footer notes
36+ /// - Breaking change markers and messages
8937#[ derive( Debug , Default , Clone ) ]
9038pub struct CommitBuilder {
9139 r#type : Option < String > ,
@@ -98,11 +46,15 @@ pub struct CommitBuilder {
9846 breaking_change_message : Option < String > , // This will filled if is_breaking_change is true
9947}
10048
101- pub struct Commit ( String ) ;
49+ /// The final commit message ready to be executed.
50+ pub struct Commit ( pub String ) ;
10251
52+ /// Errors that can occur when building a commit message.
10353#[ derive( Debug ) ]
10454pub enum BuildError {
55+ /// The commit type (feat, fix, etc.) is required but was not provided.
10556 TypeRequired ,
57+ /// The commit title/subject is required but was not provided.
10658 TitleRequired ,
10759}
10860
0 commit comments