You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
868 B

10 years ago
10 years ago
10 years ago
  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals
  3. import os
  4. from os.path import dirname as dirn
  5. import sys
  6. sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
  7. import youtube_dl
  8. BASH_COMPLETION_FILE = "youtube-dl.bash-completion"
  9. BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.in"
  10. def build_completion(opt_parser):
  11. opts_flag = []
  12. for group in opt_parser.option_groups:
  13. for option in group.option_list:
  14. # for every long flag
  15. opts_flag.append(option.get_opt_string())
  16. with open(BASH_COMPLETION_TEMPLATE) as f:
  17. template = f.read()
  18. with open(BASH_COMPLETION_FILE, "w") as f:
  19. # just using the special char
  20. filled_template = template.replace("{{flags}}", " ".join(opts_flag))
  21. f.write(filled_template)
  22. parser = youtube_dl.parseOpts()[0]
  23. build_completion(parser)