3 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
12 ZSH_COMPLETION_FILE
= 'completions/zsh/_yt-dlp'
13 ZSH_COMPLETION_TEMPLATE
= 'devscripts/zsh-completion.in'
16 def build_completion(opt_parser
):
17 opts
= [opt
for group
in opt_parser
.option_groups
18 for opt
in group
.option_list
]
19 opts_file
= [opt
for opt
in opts
if opt
.metavar
== 'FILE']
20 opts_dir
= [opt
for opt
in opts
if opt
.metavar
== 'DIR']
25 fileopts
.extend(opt
._short
_opts
)
27 fileopts
.extend(opt
._long
_opts
)
32 diropts
.extend(opt
._short
_opts
)
34 diropts
.extend(opt
._long
_opts
)
36 flags
= [opt
.get_opt_string() for opt
in opts
]
38 with
open(ZSH_COMPLETION_TEMPLATE
) as f
:
41 template
= template
.replace('{{fileopts}}', '|'.join(fileopts
))
42 template
= template
.replace('{{diropts}}', '|'.join(diropts
))
43 template
= template
.replace('{{flags}}', ' '.join(flags
))
45 with
open(ZSH_COMPLETION_FILE
, 'w') as f
:
49 parser
= yt_dlp
.parseOpts(ignore_config_files
=True)[0]
50 build_completion(parser
)