@@ -42,8 +42,8 @@ class GitMasteryREPL(cmd.Cmd):
4242 |___/
4343
4444Welcome to the Git-Mastery REPL!
45- Type 'help' for available commands, or 'exit' to quit.
46- Git-Mastery commands work with or without the 'gitmastery' prefix .
45+ Type '/ help' for available commands, or '/ exit' to quit.
46+ Use /command to run Git-Mastery commands (e.g. /verify), or 'gitmastery command' .
4747Shell commands are also supported.
4848 """
4949
@@ -70,29 +70,43 @@ def postcmd(self, stop: bool, line: str) -> bool:
7070 def precmd (self , line : str ) -> str :
7171 """Pre-process command line before execution."""
7272 stripped = line .strip ()
73- if stripped .lower (). startswith ("gitmastery " ):
74- return stripped [ len ( "gitmastery " ) :]. lstrip ()
73+ if stripped .startswith ("/ " ):
74+ return "gitmastery " + stripped [ 1 :]
7575 return line
7676
77- def default (self , line : str ) -> None :
77+ def default (self , line : str ) -> bool :
7878 """Handle commands not recognized by cmd module."""
7979 try :
8080 parts = shlex .split (line )
8181 except ValueError as e :
8282 click .echo (click .style (f"Input error: { e } " , fg = ClickColor .BRIGHT_RED ))
83- return
83+ return False
8484
8585 if not parts :
86- return
86+ return False
8787
8888 command_name = parts [0 ]
8989 args = parts [1 :]
9090
91- if command_name in GITMASTERY_COMMANDS :
92- self ._run_gitmastery_command (command_name , args )
93- return
91+ if command_name .lower () == "gitmastery" :
92+ gitmastery_command = args [0 ]
93+ if gitmastery_command in ("exit" , "quit" ):
94+ return self .do_exit ("" )
95+ elif gitmastery_command == "help" :
96+ return self .do_help ("" )
97+ elif gitmastery_command in GITMASTERY_COMMANDS :
98+ self ._run_gitmastery_command (gitmastery_command , args [1 :])
99+ else :
100+ click .echo (
101+ click .style (
102+ f"Unknown Git-Mastery command: { gitmastery_command } " ,
103+ fg = ClickColor .BRIGHT_RED ,
104+ )
105+ )
106+ return False
94107
95108 self ._run_shell_command (line )
109+ return False
96110
97111 def _run_gitmastery_command (self , command_name : str , args : List [str ]) -> None :
98112 """Execute a gitmastery command."""
@@ -127,14 +141,7 @@ def _run_gitmastery_command(self, command_name: str, args: List[str]) -> None:
127141 def _run_shell_command (self , line : str ) -> None :
128142 """Execute a shell command via subprocess."""
129143 try :
130- result = subprocess .run (line , shell = True )
131- if result .returncode != 0 :
132- click .echo (
133- click .style (
134- f"Command exited with code { result .returncode } " ,
135- fg = ClickColor .BRIGHT_YELLOW ,
136- )
137- )
144+ subprocess .run (line , shell = True )
138145 except Exception as e :
139146 click .echo (click .style (f"Shell error: { e } " , fg = ClickColor .BRIGHT_RED ))
140147
@@ -164,51 +171,44 @@ def do_cd(self, path: str) -> bool:
164171 )
165172 return False
166173
167- def do_exit (self , arg : str ) -> bool :
174+ def do_exit (self , args : str ) -> bool :
168175 """Exit the Git-Mastery REPL."""
169176 click .echo (click .style ("Goodbye!" , fg = ClickColor .BRIGHT_CYAN ))
170177 return True
171178
172- def do_quit (self , arg : str ) -> bool :
179+ def do_quit (self , args : str ) -> bool :
173180 """Exit the Git-Mastery REPL."""
174- return self .do_exit (arg )
181+ return self .do_exit (args )
175182
176- def do_help (self , arg : str ) -> bool :
183+ def do_help (self , args : str ) -> bool :
177184 """Show help for commands."""
178185 click .echo (
179186 click .style ("\n Git-Mastery Commands:" , bold = True , fg = ClickColor .BRIGHT_CYAN )
180187 )
181188 for name , command in GITMASTERY_COMMANDS .items ():
182189 help_text = (command .help or "No description available." ).strip ()
183- click .echo (f" { click .style (f'{ name :<20} ' , bold = True )} { help_text } " )
190+ click .echo (f" { click .style (f'/ { name :<20} ' , bold = True )} { help_text } " )
184191
185192 click .echo (
186193 click .style ("\n Built-in Commands:" , bold = True , fg = ClickColor .BRIGHT_CYAN )
187194 )
188195 for name , desc in [
189- ("help" , "Show this help message" ),
190- ("exit" , "Exit the REPL" ),
191- ("quit" , "Exit the REPL" ),
196+ ("/ help" , "Show this help message" ),
197+ ("/ exit" , "Exit the REPL" ),
198+ ("/ quit" , "Exit the REPL" ),
192199 ]:
193200 click .echo (f" { click .style (f'{ name :<20} ' , bold = True )} { desc } " )
194-
195- click .echo (
196- click .style (
197- "\n All other commands are passed to the shell." ,
198- fg = ClickColor .BRIGHT_YELLOW ,
199- )
200- )
201201 click .echo ()
202202 return False
203203
204204 def emptyline (self ) -> bool :
205205 """Do nothing on empty line (don't repeat last command)."""
206206 return False
207207
208- def do_EOF (self , arg : str ) -> bool :
208+ def do_EOF (self , _arg : str ) -> bool :
209209 """Handle Ctrl+D."""
210210 click .echo ()
211- return self .do_exit (arg )
211+ return self .do_exit (_arg )
212212
213213
214214@click .command ()
0 commit comments