l1ving_youtube-dl/devscripts/bash-completion.py
codesparkle d2a242afa4 #Cleanup of youtube-dl/__init__.py
* the list of contributors is now in a separate file, `AUTHORS`. Why? Because this is meta-information which applies to the entire project, not just one particular module. Also, this file can and should be extended to indicate the authors' different roles (owner, maintainer, contributor, etc). Many successful projects follow this layout, e.g. [django](https://github.com/django/django/blob/master/AUTHORS) and [Swift](https://github.com/openstack/swift). We should adopt it as well.

* Argument parsing has been extracted to `configuration.py` and the names have been changed to follow PEP-8. Unnecessarily complicated boolean conditions have been simplified

* unused imports have been removed

## TESTING
I did my best not to introduce any bugs in the process, but it doesn't seem we have any tests at all for the command-line interface and option parsing, so this will require thorough review! I'm looking forward to any comments and improvements, and please let me know if I broke `devscripts/bash-completion.py` or not.
2014-05-26 21:05:25 +10:00

29 lines
838 B
Python
Executable File

#!/usr/bin/env python
import os
from os.path import dirname as dirn
import sys
sys.path.append(dirn(dirn((os.path.abspath(__file__)))))
from youtube_dl import configuration
BASH_COMPLETION_FILE = "youtube-dl.bash-completion"
BASH_COMPLETION_TEMPLATE = "bash-completion.in"
def build_completion(opt_parser):
opts_flag = []
for group in opt_parser.option_groups:
for option in group.option_list:
#for every long flag
opts_flag.append(option.get_opt_string())
with open(BASH_COMPLETION_TEMPLATE) as f:
template = f.read()
with open(BASH_COMPLETION_FILE, "w") as f:
#just using the special char
filled_template = template.replace("{{flags}}", " ".join(opts_flag))
f.write(filled_template)
parser = configuration.parse_options()[0]
build_completion(parser)