@@ -121,6 +121,31 @@ class ConfigMerger:
121121 "CCHK_BRANCH_IGNORE_AUTHORS" : ("branch" , "ignore_authors" , parse_list ),
122122 }
123123
124+ # Mapping of CLI argument names to config keys
125+ CLI_ARG_MAPPING : Dict [str , Tuple [str , str ]] = {
126+ # Commit section
127+ "conventional_commits" : ("commit" , "conventional_commits" ),
128+ "subject_capitalized" : ("commit" , "subject_capitalized" ),
129+ "subject_imperative" : ("commit" , "subject_imperative" ),
130+ "subject_max_length" : ("commit" , "subject_max_length" ),
131+ "subject_min_length" : ("commit" , "subject_min_length" ),
132+ "allow_commit_types" : ("commit" , "allow_commit_types" ),
133+ "allow_merge_commits" : ("commit" , "allow_merge_commits" ),
134+ "allow_revert_commits" : ("commit" , "allow_revert_commits" ),
135+ "allow_empty_commits" : ("commit" , "allow_empty_commits" ),
136+ "allow_fixup_commits" : ("commit" , "allow_fixup_commits" ),
137+ "allow_wip_commits" : ("commit" , "allow_wip_commits" ),
138+ "require_body" : ("commit" , "require_body" ),
139+ "require_signed_off_by" : ("commit" , "require_signed_off_by" ),
140+ "ignore_authors" : ("commit" , "ignore_authors" ),
141+ # Branch section
142+ "conventional_branch" : ("branch" , "conventional_branch" ),
143+ "allow_branch_types" : ("branch" , "allow_branch_types" ),
144+ "allow_branch_names" : ("branch" , "allow_branch_names" ),
145+ "require_rebase_target" : ("branch" , "require_rebase_target" ),
146+ "branch_ignore_authors" : ("branch" , "ignore_authors" ),
147+ }
148+
124149 @staticmethod
125150 def parse_env_vars () -> Dict [str , Any ]:
126151 """Parse environment variables with CCHK_ prefix into config dict."""
@@ -145,77 +170,11 @@ def parse_cli_args(args: argparse.Namespace) -> Dict[str, Any]:
145170 """Parse CLI arguments into config dict."""
146171 config : Dict [str , Any ] = {"commit" : {}, "branch" : {}}
147172
148- # Commit section arguments
149- if (
150- hasattr (args , "conventional_commits" )
151- and args .conventional_commits is not None
152- ):
153- config ["commit" ]["conventional_commits" ] = args .conventional_commits
154- if (
155- hasattr (args , "subject_capitalized" )
156- and args .subject_capitalized is not None
157- ):
158- config ["commit" ]["subject_capitalized" ] = args .subject_capitalized
159- if hasattr (args , "subject_imperative" ) and args .subject_imperative is not None :
160- config ["commit" ]["subject_imperative" ] = args .subject_imperative
161- if hasattr (args , "subject_max_length" ) and args .subject_max_length is not None :
162- config ["commit" ]["subject_max_length" ] = args .subject_max_length
163- if hasattr (args , "subject_min_length" ) and args .subject_min_length is not None :
164- config ["commit" ]["subject_min_length" ] = args .subject_min_length
165- if hasattr (args , "allow_commit_types" ) and args .allow_commit_types is not None :
166- config ["commit" ]["allow_commit_types" ] = args .allow_commit_types
167- if (
168- hasattr (args , "allow_merge_commits" )
169- and args .allow_merge_commits is not None
170- ):
171- config ["commit" ]["allow_merge_commits" ] = args .allow_merge_commits
172- if (
173- hasattr (args , "allow_revert_commits" )
174- and args .allow_revert_commits is not None
175- ):
176- config ["commit" ]["allow_revert_commits" ] = args .allow_revert_commits
177- if (
178- hasattr (args , "allow_empty_commits" )
179- and args .allow_empty_commits is not None
180- ):
181- config ["commit" ]["allow_empty_commits" ] = args .allow_empty_commits
182- if (
183- hasattr (args , "allow_fixup_commits" )
184- and args .allow_fixup_commits is not None
185- ):
186- config ["commit" ]["allow_fixup_commits" ] = args .allow_fixup_commits
187- if hasattr (args , "allow_wip_commits" ) and args .allow_wip_commits is not None :
188- config ["commit" ]["allow_wip_commits" ] = args .allow_wip_commits
189- if hasattr (args , "require_body" ) and args .require_body is not None :
190- config ["commit" ]["require_body" ] = args .require_body
191- if (
192- hasattr (args , "require_signed_off_by" )
193- and args .require_signed_off_by is not None
194- ):
195- config ["commit" ]["require_signed_off_by" ] = args .require_signed_off_by
196- if hasattr (args , "ignore_authors" ) and args .ignore_authors is not None :
197- config ["commit" ]["ignore_authors" ] = args .ignore_authors
198-
199- # Branch section arguments
200- if (
201- hasattr (args , "conventional_branch" )
202- and args .conventional_branch is not None
203- ):
204- config ["branch" ]["conventional_branch" ] = args .conventional_branch
205- if hasattr (args , "allow_branch_types" ) and args .allow_branch_types is not None :
206- config ["branch" ]["allow_branch_types" ] = args .allow_branch_types
207- if hasattr (args , "allow_branch_names" ) and args .allow_branch_names is not None :
208- config ["branch" ]["allow_branch_names" ] = args .allow_branch_names
209- if (
210- hasattr (args , "require_rebase_target" )
211- and args .require_rebase_target is not None
212- ):
213- config ["branch" ]["require_rebase_target" ] = args .require_rebase_target
214- if (
215- hasattr (args , "branch_ignore_authors" )
216- and args .branch_ignore_authors is not None
217- ):
218- config ["branch" ]["ignore_authors" ] = args .branch_ignore_authors
173+ for arg_name , (section , key ) in ConfigMerger .CLI_ARG_MAPPING .items ():
174+ if hasattr (args , arg_name ):
175+ value = getattr (args , arg_name )
176+ if value is not None :
177+ config [section ][key ] = value
219178
220179 # Remove empty sections
221180 config = {k : v for k , v in config .items () if v }
0 commit comments