diff --git a/tools/make_man.py b/tools/make_man.py index 718d7ec41ec7efa1c54849ed4699a483bcc9d129..cc11121a50b409d48144db6dd57edb9cb31abaa1 100755 --- a/tools/make_man.py +++ b/tools/make_man.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright(C) 2010-2014 Laurent Bachelier +# Copyright(C) 2010-2018 Laurent Bachelier # # This file is part of weboob. # @@ -28,13 +28,14 @@ import sys import tempfile import time - from datetime import datetime -from weboob.tools.application.base import Application +from textwrap import dedent +from weboob.tools.application.base import Application BASE_PATH = os.path.join(os.path.dirname(__file__), os.pardir) DEST_DIR = 'man' +COMP_PATH = 'tools/weboob_bash_completion' class ManpageHelpFormatter(optparse.HelpFormatter): @@ -107,6 +108,7 @@ def format_option_strings(self, option): def main(): scripts_path = os.path.join(BASE_PATH, "scripts") files = os.listdir(scripts_path) + completions = dict() # Create a fake "scripts" modules to import the scripts into sys.modules["scripts"] = imp.new_module("scripts") @@ -132,11 +134,12 @@ def main(): # Find the applications we can handle for klass in script.__dict__.values(): if inspect.isclass(klass) and issubclass(klass, Application) and klass.VERSION: - analyze_application(klass, fname) + completions[fname] = analyze_application(klass, fname) finally: # Cleanup compiled files if needed if (os.path.isfile(tmpfile + "c")): os.unlink(tmpfile + "c") + write_completions(completions) def format_title(title): @@ -241,5 +244,37 @@ def analyze_application(app, script_name): manfile.write('%s\n' % line.lstrip().encode('utf-8')) print("wrote %s/%s.1" % (DEST_DIR, script_name)) + return application._shell_completion_items() + + +def write_completions(completions): + compscript = dedent(''' + # Weboob completion for Bash (automatically generated by tools/make_man.sh) + # + # vim: filetype=sh expandtab softtabstop=4 shiftwidth=4 + # + # This file is part of weboob. + # + # This script can be distributed under the same license as the + # weboob or bash packages. + ''') + for name, items in completions.items(): + compscript += dedent(''' + _weboob_{1}() + {{ + local cur args + + COMPREPLY=() + cur=${{COMP_WORDS[COMP_CWORD]}} + args="{2}" + + COMPREPLY=( $(compgen -o default -W "${{args}}" -- "$cur" ) ) + }} + complete -F _weboob_{1} {0} + ''').format(name, name.replace('-', '_'), ' '.join(items)) + with open(os.path.join(BASE_PATH, COMP_PATH), 'w') as f: + f.write(compscript) + + if __name__ == '__main__': sys.exit(main()) diff --git a/tools/weboob_bash_completion b/tools/weboob_bash_completion index be626977b4fde1db9ab9aa04ab2a90b9f6117fb8..e565d871a22fbce6ab47ce1cb1513f615a7ea2eb 100644 --- a/tools/weboob_bash_completion +++ b/tools/weboob_bash_completion @@ -1,42 +1,549 @@ -# Weboob completion for Bash + +# Weboob completion for Bash (automatically generated by tools/make_man.sh) # # vim: filetype=sh expandtab softtabstop=4 shiftwidth=4 # -# Copyright(C) 2010-2011 Christophe Benz -# # This file is part of weboob. # -# weboob is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# weboob is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with weboob. If not, see . -# # This script can be distributed under the same license as the # weboob or bash packages. -_weboob() +_weboob_weboob_config() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_weboob_config weboob-config + +_weboob_weboob_repos() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_weboob_repos weboob-repos + +_weboob_weboob_debug() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_weboob_debug weboob-debug + +_weboob_qcookboob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qcookboob qcookboob + +_weboob_boobathon() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_boobathon boobathon + +_weboob_galleroob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_galleroob galleroob + +_weboob_webcontentedit() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_webcontentedit webcontentedit + +_weboob_suboob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_suboob suboob + +_weboob_wetboobs() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_wetboobs wetboobs + +_weboob_boobank() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_boobank boobank + +_weboob_qwebcontentedit() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qwebcontentedit qwebcontentedit + +_weboob_qhavedate() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qhavedate qhavedate + +_weboob_booblyrics() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_booblyrics booblyrics + +_weboob_qboobmsg() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qboobmsg qboobmsg + +_weboob_monboob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_monboob monboob + +_weboob_handjoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_handjoob handjoob + +_weboob_translaboob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_translaboob translaboob + +_weboob_videoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_videoob videoob + +_weboob_weboob_config_qt() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_weboob_config_qt weboob-config-qt + +_weboob_flatboob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_flatboob flatboob + +_weboob_radioob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_radioob radioob + +_weboob_qflatboob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qflatboob qflatboob + +_weboob_geolooc() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_geolooc geolooc + +_weboob_weboob_cli() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_weboob_cli weboob-cli + +_weboob_parceloob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_parceloob parceloob + +_weboob_qhandjoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qhandjoob qhandjoob + +_weboob_cineoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_cineoob cineoob + +_weboob_weboorrents() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_weboorrents weboorrents + +_weboob_boobmsg() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_boobmsg boobmsg + +_weboob_traveloob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_traveloob traveloob + +_weboob_shopoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_shopoob shopoob + +_weboob_boobill() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_boobill boobill + +_weboob_boobcoming() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_boobcoming boobcoming + +_weboob_boobtracker() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_boobtracker boobtracker + +_weboob_pastoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_pastoob pastoob + +_weboob_boobsize() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_boobsize boobsize + +_weboob_boobooks() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_boobooks boobooks + +_weboob_comparoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_comparoob comparoob + +_weboob_qbooblyrics() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qbooblyrics qbooblyrics + +_weboob_cookboob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_cookboob cookboob + +_weboob_qcineoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qcineoob qcineoob + +_weboob_qvideoob() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qvideoob qvideoob + +_weboob_weboob() { local cur args COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} - args="$(${COMP_WORDS[0]} --shell-completion)" + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) } +complete -F _weboob_weboob weboob + +_weboob_qgalleroob() +{ + local cur args -hash weboob-config 2>/dev/null && -weboob_applications=$(weboob-config applications 2>/dev/null) -hash -d weboob-config -for application in $weboob_applications -do - complete -F _weboob $application -done + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_qgalleroob qgalleroob + +_weboob_havedate() +{ + local cur args + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + args="-e --insecure -b -I --exclude-backends -h --version --auto-update --backends --help --nss" + + COMPREPLY=( $(compgen -o default -W "${args}" -- "$cur" ) ) +} +complete -F _weboob_havedate havedate diff --git a/weboob/tools/application/base.py b/weboob/tools/application/base.py index c7c29ee1b68011c32ad31e1431c9f8dfe053ccfc..c5bce9cb12bcd26d3fd7d1a2f7469cf3e9ff06f8 100644 --- a/weboob/tools/application/base.py +++ b/weboob/tools/application/base.py @@ -354,15 +354,19 @@ def bcall_errors_handler(self, errors, debugmsg='Use --debug option to print bac if ask_debug_mode: print(debugmsg, file=self.stderr) + def _shell_completion_items(self): + items = set() + for option in self._parser.option_list: + if option.help is not optparse.SUPPRESS_HELP: + items.update(str(option).split('/')) + items.update(self._get_completions()) + return items + def parse_args(self, args): self.options, args = self._parser.parse_args(args) if self.options.shell_completion: - items = set() - for option in self._parser.option_list: - if option.help is not optparse.SUPPRESS_HELP: - items.update(str(option).split('/')) - items.update(self._get_completions()) + items = self._shell_completion_items() print(' '.join(items)) sys.exit(0)