@@ -169,7 +169,7 @@ def build(ctx, stack_dir, stack_env, log_level, env_file,
169169 """Create or update resources."""
170170
171171 from .cmd .build import StackQLProvisioner
172-
172+
173173 stackql , env_vars = setup_command_context (
174174 ctx , stack_dir , stack_env , log_level , env_file ,
175175 env , dry_run , show_queries , on_failure , custom_registry , download_dir , 'build'
@@ -236,7 +236,7 @@ def teardown(ctx, stack_dir, stack_env, log_level, env_file,
236236def test (ctx , stack_dir , stack_env , log_level , env_file ,
237237 env , dry_run , show_queries , on_failure , custom_registry , download_dir ):
238238 """Run test queries for the stack."""
239-
239+
240240 from .cmd .test import StackQLTestRunner
241241
242242 stackql , env_vars = setup_command_context (
@@ -474,100 +474,98 @@ def init(stack_name, provider):
474474def completion (shell , install ):
475475 """
476476 Shell tab completion for stackql-deploy.
477-
478477 Examples:
479478 eval "$(stackql-deploy completion bash)" # activate now
480479 stackql-deploy completion bash --install # install permanently
481480 stackql-deploy completion # auto-detect shell
482481 """
483- from pathlib import Path
484-
482+
485483 # Auto-detect shell if not provided
486484 if not shell :
487485 shell = os .environ .get ("SHELL" , "" ).split ("/" )[- 1 ] or "bash"
488486 shell = shell .lower ()
489-
487+
490488 # Map shells to completion script files
491489 completion_scripts = {
492490 "bash" : "stackql-deploy-completion.bash" ,
493491 "zsh" : "stackql-deploy-completion.zsh" ,
494492 "fish" : "stackql-deploy-completion.fish" ,
495493 "powershell" : "stackql-deploy-completion.ps1"
496494 }
497-
495+
498496 script_name = completion_scripts .get (shell )
499497 if not script_name :
500498 click .echo (f"❌ Shell '{ shell } ' not supported. Supported: bash, zsh, fish, powershell" , err = True )
501499 sys .exit (1 )
502-
500+
503501 # Find the completion script
504502 script_path = _find_completion_script (script_name )
505503 if not script_path :
506504 click .echo (f"❌ Completion script not found: { script_name } " , err = True )
507505 sys .exit (1 )
508-
506+
509507 # Output script for eval/source (default behavior)
510508 if not install :
511509 with open (script_path , 'r' ) as f :
512510 click .echo (f .read ())
513511 return
514-
512+
515513 # Install to shell profile
516514 _install_completion_for_shell (shell , script_path )
517515
518516def _find_completion_script (script_name ):
519517 """Find completion script in development or installed locations."""
520518 from pathlib import Path
521-
519+
522520 # Development mode: relative to project root
523521 cli_file = Path (__file__ ).resolve ()
524522 project_root = cli_file .parent .parent
525523 dev_path = project_root / "shell_completions" / script_name
526-
524+
527525 if dev_path .exists ():
528526 logger .debug (f"Found completion script: { dev_path } " )
529527 return dev_path
530-
528+
531529 # Installed mode: check common install locations
532530 for prefix in [sys .prefix , sys .base_prefix , '/usr' , '/usr/local' ]:
533531 installed_path = Path (prefix ) / "share" / "stackql-deploy" / "completions" / script_name
534532 if installed_path .exists ():
535533 logger .debug (f"Found completion script: { installed_path } " )
536534 return installed_path
537-
535+
538536 logger .error (f"Completion script { script_name } not found" )
539537 return None
540538
541539def _install_completion_for_shell (shell , script_path ):
542540 """Install completion to shell profile."""
543541 from pathlib import Path
544-
542+
545543 profiles = {
546544 "bash" : Path .home () / ".bashrc" ,
547545 "zsh" : Path .home () / ".zshrc" ,
548546 "fish" : Path .home () / ".config/fish/config.fish" ,
549547 "powershell" : Path .home () / "Documents/PowerShell/Microsoft.PowerShell_profile.ps1"
550548 }
551-
549+
552550 eval_commands = {
553551 "bash" : 'eval "$(stackql-deploy completion bash)"' ,
554552 "zsh" : 'eval "$(stackql-deploy completion zsh)"' ,
555553 "fish" : 'stackql-deploy completion fish | source' ,
556554 "powershell" : '. (stackql-deploy completion powershell)'
557555 }
558-
556+
559557 profile_path = profiles .get (shell )
560558 eval_cmd = eval_commands .get (shell )
561-
559+
562560 if not profile_path :
563561 click .echo (f"❌ Unknown profile for { shell } " , err = True )
564562 return
565-
563+
566564 # Ensure profile directory and file exist
567565 profile_path .parent .mkdir (parents = True , exist_ok = True )
568566 if not profile_path .exists ():
569567 profile_path .touch ()
570-
568+
571569 # Check if already installed
572570 try :
573571 content = profile_path .read_text ()
@@ -578,7 +576,7 @@ def _install_completion_for_shell(shell, script_path):
578576 except Exception as e :
579577 click .echo (f"❌ Error reading profile: { e } " , err = True )
580578 return
581-
579+
582580 # Append completion line
583581 try :
584582 with open (profile_path , "a" ) as f :
@@ -596,7 +594,7 @@ def _show_activation_instructions(shell):
596594 "fish" : 'source ~/.config/fish/config.fish' ,
597595 "powershell" : '. $PROFILE'
598596 }
599-
597+
600598 click .echo (f"🚀 Activate now: { instructions .get (shell , 'restart your shell' )} " )
601599 click .echo ("✨ Or restart your terminal" )
602600
0 commit comments