1- """Shell completion management commands"""
1+ """Shell completion management commands and completion definitions for dev commands. """
22
33import subprocess
44import sys
55from pathlib import Path
66
77import click
88
9+ # ============================================================================
10+ # Completion Management Commands
11+ # ============================================================================
12+
913
1014@click .group ()
1115def completion () -> None :
@@ -18,7 +22,7 @@ def test_completion() -> None:
1822 """Test shell completion functionality"""
1923 click .echo ("Running completion tests..." )
2024 result = subprocess .run (
21- ["python" , "commands/ tests/test_cmd_completion.py" ],
25+ ["python" , "tests/commands /test_cmd_completion.py" ],
2226 capture_output = True ,
2327 text = True ,
2428 )
@@ -94,3 +98,153 @@ def sync() -> None:
9498 except Exception as e :
9599 click .echo (f"❌ Failed to generate completion: { e } " , err = True )
96100 sys .exit (1 )
101+
102+
103+ # ============================================================================
104+ # Completion Definitions for Dev Commands
105+ # ============================================================================
106+
107+
108+ def get_dev_completions (ctx : object , args : list [str ], incomplete : str ) -> list [str ]:
109+ """Get completions for dev commands.
110+
111+ Args:
112+ ctx: Click context
113+ args: Already provided arguments
114+ incomplete: Current incomplete word
115+
116+ Returns:
117+ List of completion suggestions
118+ """
119+ # Get the subcommand if specified
120+ if not args or args [0 ] == "dev" :
121+ # Suggest dev subcommands
122+ commands = [
123+ "all" ,
124+ "format" ,
125+ "lint" ,
126+ "typecheck" ,
127+ "test" ,
128+ "precommit" ,
129+ "completion" ,
130+ ]
131+ return [cmd for cmd in commands if cmd .startswith (incomplete )]
132+
133+ subcommand = args [0 ] if args else None
134+
135+ # Delegate to specific completers
136+ if subcommand == "format" :
137+ return complete_format (ctx , args [1 :], incomplete )
138+ elif subcommand == "lint" :
139+ return complete_lint (ctx , args [1 :], incomplete )
140+ elif subcommand == "typecheck" :
141+ return complete_typecheck (ctx , args [1 :], incomplete )
142+ elif subcommand == "test" :
143+ return complete_test (ctx , args [1 :], incomplete )
144+ elif subcommand == "precommit" :
145+ return complete_precommit (ctx , args [1 :], incomplete )
146+ elif subcommand == "completion" :
147+ return complete_completion_cmd (ctx , args [1 :], incomplete )
148+
149+ return []
150+
151+
152+ def complete_all (ctx : object , args : list [str ], incomplete : str ) -> list [str ]:
153+ """Completions for dev all command."""
154+ if incomplete .startswith ("-" ):
155+ options = ["--verbose" , "--quiet" , "--stop-on-error" ]
156+ return [opt for opt in options if opt .startswith (incomplete )]
157+ return []
158+
159+
160+ def complete_format (ctx : object , args : list [str ], incomplete : str ) -> list [str ]:
161+ """Completions for dev format command."""
162+ if incomplete .startswith ("-" ):
163+ options = ["--check" , "--diff" , "--verbose" ]
164+ return [opt for opt in options if opt .startswith (incomplete )]
165+
166+ # Suggest Python files
167+ if not incomplete .startswith ("-" ):
168+ py_files = list (Path .cwd ().glob ("**/*.py" ))
169+ suggestions = [str (f .relative_to (Path .cwd ())) for f in py_files ]
170+ return [s for s in suggestions if s .startswith (incomplete )][:10 ] # Limit to 10
171+
172+ return []
173+
174+
175+ def complete_lint (ctx : object , args : list [str ], incomplete : str ) -> list [str ]:
176+ """Completions for dev lint command."""
177+ if incomplete .startswith ("-" ):
178+ options = ["--fix" , "--show-fixes" , "--verbose" ]
179+ return [opt for opt in options if opt .startswith (incomplete )]
180+
181+ # Suggest Python files
182+ if not incomplete .startswith ("-" ):
183+ py_files = list (Path .cwd ().glob ("**/*.py" ))
184+ suggestions = [str (f .relative_to (Path .cwd ())) for f in py_files ]
185+ return [s for s in suggestions if s .startswith (incomplete )][:10 ]
186+
187+ return []
188+
189+
190+ def complete_typecheck (ctx : object , args : list [str ], incomplete : str ) -> list [str ]:
191+ """Completions for dev typecheck command."""
192+ if incomplete .startswith ("-" ):
193+ options = ["--strict" , "--ignore-missing-imports" , "--verbose" ]
194+ return [opt for opt in options if opt .startswith (incomplete )]
195+
196+ # Suggest directories
197+ if not incomplete .startswith ("-" ):
198+ dirs = [
199+ d for d in Path .cwd ().iterdir () if d .is_dir () and not d .name .startswith ("." )
200+ ]
201+ suggestions = [d .name for d in dirs ]
202+ return [s for s in suggestions if s .startswith (incomplete )]
203+
204+ return []
205+
206+
207+ def complete_test (ctx : object , args : list [str ], incomplete : str ) -> list [str ]:
208+ """Completions for dev test command."""
209+ if incomplete .startswith ("-" ):
210+ options = ["--coverage" , "--verbose" , "--failfast" , "--parallel" ]
211+ return [opt for opt in options if opt .startswith (incomplete )]
212+
213+ # Suggest test files
214+ if not incomplete .startswith ("-" ):
215+ test_files = list (Path .cwd ().glob ("**/test_*.py" ))
216+ suggestions = [str (f .relative_to (Path .cwd ())) for f in test_files ]
217+ return [s for s in suggestions if s .startswith (incomplete )][:10 ]
218+
219+ return []
220+
221+
222+ def complete_precommit (ctx : object , args : list [str ], incomplete : str ) -> list [str ]:
223+ """Completions for dev precommit command."""
224+ if incomplete .startswith ("-" ):
225+ options = ["--fix" , "--ci" , "--verbose" ]
226+ return [opt for opt in options if opt .startswith (incomplete )]
227+ return []
228+
229+
230+ def complete_completion_cmd (ctx : object , args : list [str ], incomplete : str ) -> list [str ]:
231+ """Completions for dev completion command."""
232+ # If no subcommand yet
233+ if not args :
234+ subcommands = ["test" , "sync" ]
235+ return [cmd for cmd in subcommands if cmd .startswith (incomplete )]
236+
237+ return []
238+
239+
240+ # Export completion registry for modular completion system
241+ COMPLETIONS = {
242+ "dev" : get_dev_completions ,
243+ "all" : complete_all ,
244+ "format" : complete_format ,
245+ "lint" : complete_lint ,
246+ "typecheck" : complete_typecheck ,
247+ "test" : complete_test ,
248+ "precommit" : complete_precommit ,
249+ "completion" : complete_completion_cmd ,
250+ }
0 commit comments