1818
1919from .cli import console
2020from .cli .cli_handler import CommitLoom
21+ from . import __version__
22+ from .config .settings import config
2123
2224
2325def handle_error (error : BaseException ) -> None :
@@ -30,6 +32,7 @@ def handle_error(error: BaseException) -> None:
3032
3133@click .group ()
3234@click .option ("-d" , "--debug" , is_flag = True , help = "Enable debug logging" )
35+ @click .version_option (version = __version__ , prog_name = "CommitLoom" )
3336@click .pass_context
3437def cli (ctx , debug : bool ) -> None :
3538 """Create structured git commits with AI-generated messages."""
@@ -43,8 +46,14 @@ def cli(ctx, debug: bool) -> None:
4346@cli .command (help = "Generate an AI-powered commit message and commit your changes" )
4447@click .option ("-y" , "--yes" , is_flag = True , help = "Skip all confirmation prompts" )
4548@click .option ("-c" , "--combine" , is_flag = True , help = "Combine all changes into a single commit" )
49+ @click .option (
50+ "-m" ,
51+ "--model" ,
52+ type = click .Choice (list (config .model_costs .keys ())),
53+ help = f"Specify the AI model to use (default: { config .default_model } )"
54+ )
4655@click .pass_context
47- def commit (ctx , yes : bool , combine : bool ) -> None :
56+ def commit (ctx , yes : bool , combine : bool , model : str | None ) -> None :
4857 """Generate commit message and commit changes."""
4958 debug = ctx .obj .get ("DEBUG" , False )
5059
@@ -56,6 +65,12 @@ def commit(ctx, yes: bool, combine: bool) -> None:
5665
5766 # Initialize with test_mode
5867 loom = CommitLoom (test_mode = test_mode , api_key = api_key if api_key else None )
68+
69+ # Set custom model if specified
70+ if model :
71+ os .environ ["COMMITLOOM_MODEL" ] = model
72+ console .print_info (f"Using model: { model } " )
73+
5974 loom .run (auto_commit = yes , combine_commits = combine , debug = debug )
6075 except (KeyboardInterrupt , Exception ) as e :
6176 handle_error (e )
@@ -79,18 +94,51 @@ def stats(ctx) -> None:
7994 sys .exit (1 )
8095
8196
97+ @cli .command (help = "Display detailed help information" )
98+ def help () -> None :
99+ """Display detailed help information about CommitLoom."""
100+ help_text = f"""
101+ [bold cyan]CommitLoom v{ __version__ } [/bold cyan]
102+ [italic]Weave perfect git commits with AI-powered intelligence[/italic]
103+
104+ [bold]Basic Usage:[/bold]
105+ loom Run the default commit command
106+ loom commit Generate commit message for staged changes
107+ loom commit -y Skip confirmation prompts
108+ loom commit -c Combine all changes into a single commit
109+ loom commit -m MODEL Specify AI model to use
110+ loom stats Show usage statistics
111+ loom --version Display version information
112+ loom help Show this help message
113+
114+ [bold]Available Models:[/bold]
115+ { ', ' .join (config .model_costs .keys ())}
116+ Default: { config .default_model }
117+
118+ [bold]Environment Setup:[/bold]
119+ 1. Set OPENAI_API_KEY in your environment or in a .env file
120+ 2. Stage your changes with 'git add'
121+ 3. Run 'loom' to generate and apply commit messages
122+
123+ [bold]Documentation:[/bold]
124+ Full documentation: https://github.com/Arakiss/commitloom#readme
125+ """
126+ console .console .print (help_text )
127+
128+
82129# For backwards compatibility, default to commit command if no subcommand provided
83130def main () -> None :
84131 """Entry point for the CLI."""
85- # Check if the first argument is a known command, if not, insert 'commit'
86- known_commands = ['commit' , 'stats' ]
87-
88- if len (sys .argv ) > 1 and not sys .argv [1 ].startswith ('-' ) and sys .argv [1 ] not in known_commands :
132+ known_commands = ['commit' , 'stats' , 'help' ]
133+ commit_options = ['-y' , '--yes' , '-c' , '--combine' , '-m' , '--model' ]
134+
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
138+ 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 :
89141 sys .argv .insert (1 , 'commit' )
90-
91- # If no arguments provided, add 'commit' as the default command
92- if len (sys .argv ) == 1 :
93- sys .argv .append ('commit' )
94142
95143 cli (obj = {})
96144
0 commit comments