@@ -46,16 +46,21 @@ def cli(ctx, debug: bool, version: bool = False) -> None:
4646@cli .command (help = "Generate an AI-powered commit message and commit your changes" )
4747@click .option ("-y" , "--yes" , is_flag = True , help = "Skip all confirmation prompts" )
4848@click .option ("-c" , "--combine" , is_flag = True , help = "Combine all changes into a single commit" )
49+ @click .option ("-d" , "--debug" , is_flag = True , help = "Enable debug logging" )
4950@click .option (
5051 "-m" ,
5152 "--model" ,
5253 type = str , # Permitir cualquier string
5354 help = f"Specify any OpenAI model to use (default: { config .default_model } )"
5455)
5556@click .pass_context
56- def commit (ctx , yes : bool , combine : bool , model : str | None ) -> None :
57+ def commit (ctx , yes : bool , combine : bool , debug : bool , model : str | None ) -> None :
5758 """Generate commit message and commit changes."""
58- debug = ctx .obj .get ("DEBUG" , False )
59+ # Use debug from either local flag or global context
60+ debug = debug or ctx .obj .get ("DEBUG" , False )
61+
62+ if debug :
63+ console .setup_logging (debug = True )
5964
6065 try :
6166 test_mode = "pytest" in sys .modules
@@ -142,6 +147,9 @@ def main() -> None:
142147 cli (obj = {})
143148 return
144149
150+ # Check if we have debug option anywhere in the arguments
151+ has_debug = any (arg in debug_options for arg in sys .argv [1 :])
152+
145153 # Check the first argument
146154 first_arg = sys .argv [1 ]
147155
@@ -150,23 +158,15 @@ def main() -> None:
150158 cli (obj = {})
151159 return
152160
153- # If it starts with any commit-specific option, it's intended for the commit command
154- if first_arg in commit_options :
155- sys .argv .insert (1 , 'commit' )
156- cli (obj = {})
157- return
158-
159- # If it's a global option, don't insert commit
160- if any (first_arg == opt for opt in global_options ):
161+ # If it's a global option without debug, don't insert commit
162+ if first_arg in global_options and not has_debug :
161163 cli (obj = {})
162164 return
163165
164- # If it's a debug option, add 'commit' after it to enable debugging for the commit command
165- if first_arg in debug_options :
166- # Check if there's a command after the debug flag
167- if len (sys .argv ) <= 2 or (len (sys .argv ) > 2 and (sys .argv [2 ].startswith ('-' ) and sys .argv [2 ] not in known_commands )):
168- # No command after debug flag, insert commit
169- sys .argv .insert (2 , 'commit' )
166+ # If we have debug option anywhere, or commit-specific options, add commit command
167+ if has_debug or first_arg in commit_options or any (arg in commit_options for arg in sys .argv [1 :]):
168+ # Insert 'commit' at the beginning of options
169+ sys .argv .insert (1 , 'commit' )
170170 cli (obj = {})
171171 return
172172
0 commit comments