99
1010# Load environment variables before any imports
1111env_path = os .path .join (os .path .dirname (__file__ ), ".." , ".env" )
12- print (f"Loading .env from: { os .path .abspath (env_path )} " )
1312load_dotenv (dotenv_path = env_path )
1413
15- # Debug: Check if API key is loaded
16- api_key = os .getenv ("OPENAI_API_KEY" )
17- print (f"API Key loaded: { 'Yes' if api_key else 'No' } " )
18-
1914from . import __version__
2015from .cli import console
2116from .cli .cli_handler import CommitLoom
@@ -32,14 +27,14 @@ def handle_error(error: BaseException) -> None:
3227
3328@click .group ()
3429@click .option ("-d" , "--debug" , is_flag = True , help = "Enable debug logging" )
35- @click .option ("-v" , "--version" , is_flag = True , callback = lambda ctx , param , value :
30+ @click .option ("-v" , "--version" , is_flag = True , callback = lambda ctx , param , value :
3631 value and print (f"CommitLoom, version { __version__ } " ) or exit (0 ) if value else None ,
3732 help = "Show the version and exit." )
3833@click .pass_context
3934def cli (ctx , debug : bool , version : bool = False ) -> None :
4035 """Create structured git commits with AI-generated messages."""
4136 ctx .ensure_object (dict )
42-
37+
4338 # Check for debug mode in config file or environment variable
4439 debug_env = os .getenv ("DEBUG_MODE" , "" ).lower () in ("true" , "1" , "yes" )
4540 ctx .obj ["DEBUG" ] = debug or debug_env
@@ -52,8 +47,8 @@ def cli(ctx, debug: bool, version: bool = False) -> None:
5247@click .option ("-y" , "--yes" , is_flag = True , help = "Skip all confirmation prompts" )
5348@click .option ("-c" , "--combine" , is_flag = True , help = "Combine all changes into a single commit" )
5449@click .option (
55- "-m" ,
56- "--model" ,
50+ "-m" ,
51+ "--model" ,
5752 type = str , # Permitir cualquier string
5853 help = f"Specify any OpenAI model to use (default: { config .default_model } )"
5954)
@@ -140,32 +135,32 @@ def main() -> None:
140135 debug_options = ['-d' , '--debug' ]
141136 # These are options specific to the commit command
142137 commit_options = ['-y' , '--yes' , '-c' , '--combine' , '-m' , '--model' ]
143-
138+
144139 # If no arguments, simply add the default commit command
145140 if len (sys .argv ) == 1 :
146141 sys .argv .insert (1 , 'commit' )
147142 cli (obj = {})
148143 return
149-
144+
150145 # Check the first argument
151146 first_arg = sys .argv [1 ]
152-
147+
153148 # If it's already a known command, no need to modify
154149 if first_arg in known_commands :
155150 cli (obj = {})
156151 return
157-
152+
158153 # If it starts with any commit-specific option, it's intended for the commit command
159154 if first_arg in commit_options :
160155 sys .argv .insert (1 , 'commit' )
161156 cli (obj = {})
162157 return
163-
158+
164159 # If it's a global option, don't insert commit
165160 if any (first_arg == opt for opt in global_options ):
166161 cli (obj = {})
167162 return
168-
163+
169164 # If it's a debug option, add 'commit' after it to enable debugging for the commit command
170165 if first_arg in debug_options :
171166 # Check if there's a command after the debug flag
@@ -174,12 +169,12 @@ def main() -> None:
174169 sys .argv .insert (2 , 'commit' )
175170 cli (obj = {})
176171 return
177-
178- # For any other non-option argument that's not a known command,
172+
173+ # For any other non-option argument that's not a known command,
179174 # assume it's meant for the commit command
180175 if not first_arg .startswith ('-' ):
181176 sys .argv .insert (1 , 'commit' )
182-
177+
183178 cli (obj = {})
184179
185180
0 commit comments