1010from typing import Iterable
1111
1212import numpy as np
13+ from argcomplete import autocomplete , shellcode
1314from PIL import Image
1415
1516from vesskel .config import (
@@ -76,6 +77,20 @@ def _parse_args() -> argparse.Namespace:
7677 )
7778 validate_parser .add_argument ("--config" , required = True , help = "Config JSON path." )
7879
80+ completions_parser = subparsers .add_parser (
81+ "completions" ,
82+ help = "Print shell completion script to stdout." ,
83+ )
84+ completions_parser .add_argument (
85+ "shell" ,
86+ choices = ("bash" , "zsh" , "powershell" ),
87+ help = "Target shell." ,
88+ )
89+
90+ try :
91+ autocomplete (parser )
92+ except ImportError :
93+ pass
7994 return parser .parse_args ()
8095
8196
@@ -244,6 +259,12 @@ def _validate_config(args: argparse.Namespace) -> int:
244259 return 0
245260
246261
262+ def _completions (args : argparse .Namespace ) -> int :
263+
264+ print (shellcode (["vesskel" ], shell = args .shell ))
265+ return 0
266+
267+
247268def main () -> int :
248269 args = _parse_args ()
249270 if args .command == "run" :
@@ -252,6 +273,8 @@ def main() -> int:
252273 return _config_init (args )
253274 if args .command == "validate-config" :
254275 return _validate_config (args )
276+ if args .command == "completions" :
277+ return _completions (args )
255278 raise ValueError (f"Unknown command: { args .command } " )
256279
257280
0 commit comments