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.

26 lines
821 B

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