1616api_key = os .getenv ("OPENAI_API_KEY" )
1717print (f"API Key loaded: { 'Yes' if api_key else 'No' } " )
1818
19+ from . import __version__
1920from .cli import console
2021from .cli .cli_handler import CommitLoom
21- from . import __version__
2222from .config .settings import config
2323
2424
@@ -32,9 +32,11 @@ def handle_error(error: BaseException) -> None:
3232
3333@click .group ()
3434@click .option ("-d" , "--debug" , is_flag = True , help = "Enable debug logging" )
35- @click .version_option (version = __version__ , prog_name = "CommitLoom" )
35+ @click .option ("-v" , "--version" , is_flag = True , callback = lambda ctx , param , value :
36+ value and print (f"CommitLoom, version { __version__ } " ) or exit (0 ) if value else None ,
37+ help = "Show the version and exit." )
3638@click .pass_context
37- def cli (ctx , debug : bool ) -> None :
39+ def cli (ctx , debug : bool , version : bool = False ) -> None :
3840 """Create structured git commits with AI-generated messages."""
3941 ctx .ensure_object (dict )
4042 ctx .obj ["DEBUG" ] = debug
@@ -130,16 +132,41 @@ def help() -> None:
130132def main () -> None :
131133 """Entry point for the CLI."""
132134 known_commands = ['commit' , 'stats' , 'help' ]
135+ # These are options for the main CLI group
136+ global_options = ['-d' , '--debug' , '-v' , '--version' , '--help' ]
137+ # These are options specific to the commit command
133138 commit_options = ['-y' , '--yes' , '-c' , '--combine' , '-m' , '--model' ]
134139
135- # If no arguments or only options without a command, add 'commit' as the default command
136- if len (sys .argv ) == 1 or (len (sys .argv ) > 1 and sys .argv [1 ].startswith ('-' )):
137- # Insert 'commit' as the first argument
140+ # If no arguments, simply add the default commit command
141+ if len (sys .argv ) == 1 :
142+ sys .argv .insert (1 , 'commit' )
143+ cli (obj = {})
144+ return
145+
146+ # Check the first argument
147+ first_arg = sys .argv [1 ]
148+
149+ # If it's already a known command, no need to modify
150+ if first_arg in known_commands :
151+ cli (obj = {})
152+ return
153+
154+ # If it starts with -y or --yes, it's intended for the commit command
155+ if first_arg in ['-y' , '--yes' ]:
138156 sys .argv .insert (1 , 'commit' )
139- # If the first argument is not a known command and not an option, insert 'commit'
140- elif len (sys .argv ) > 1 and not sys .argv [1 ].startswith ('-' ) and sys .argv [1 ] not in known_commands :
157+ cli (obj = {})
158+ return
159+
160+ # If it's a global option, don't insert commit
161+ if any (first_arg == opt for opt in global_options ):
162+ cli (obj = {})
163+ return
164+
165+ # For any other non-option argument that's not a known command,
166+ # assume it's meant for the commit command
167+ if not first_arg .startswith ('-' ):
141168 sys .argv .insert (1 , 'commit' )
142-
169+
143170 cli (obj = {})
144171
145172
0 commit comments