franta-hg@81: #!/usr/bin/perl franta-hg@81: franta-hg@83: # SQL-DK franta-hg@83: # Copyright © 2013 František Kučera (frantovo.cz) franta-hg@83: # franta-hg@83: # This program is free software: you can redistribute it and/or modify franta-hg@83: # it under the terms of the GNU General Public License as published by franta-hg@83: # the Free Software Foundation, either version 3 of the License, or franta-hg@83: # (at your option) any later version. franta-hg@83: # franta-hg@83: # This program is distributed in the hope that it will be useful, franta-hg@83: # but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@83: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@83: # GNU General Public License for more details. franta-hg@83: # franta-hg@83: # You should have received a copy of the GNU General Public License franta-hg@83: # along with this program. If not, see . franta-hg@83: franta-hg@83: franta-hg@81: # Parses Java source code from STDIN and generates script for BASH completion franta-hg@81: # Input (in this order): franta-hg@81: # info/globalcode/sql/dk/Constants.java franta-hg@81: # info/globalcode/sql/dk/formatting/* franta-hg@81: # info/globalcode/sql/dk/CLIParser.java franta-hg@81: franta-hg@82: # TODO: support database/formatter names with spaces franta-hg@82: franta-hg@81: use strict; franta-hg@81: use warnings; franta-hg@81: franta-hg@81: my $configDir = "~"; franta-hg@81: franta-hg@81: while (<>) { franta-hg@81: if (/"(.*?)".*? \/\/\s*bash-completion:dir/) { franta-hg@81: $configDir .= "/$1"; franta-hg@81: last; franta-hg@81: } franta-hg@81: } franta-hg@81: franta-hg@82: my $databasesFile = "$configDir/bash-completion/databases"; franta-hg@82: my $formattersFile = "$configDir/bash-completion/formatters"; franta-hg@82: franta-hg@110: print '#have sql-dk && franta-hg@81: _sql_dk() franta-hg@81: { franta-hg@81: local cur prev franta-hg@81: franta-hg@81: COMPREPLY=() franta-hg@81: cur=${COMP_WORDS[COMP_CWORD]} franta-hg@81: prev=${COMP_WORDS[COMP_CWORD-1]} franta-hg@81: franta-hg@81: case "$prev" in franta-hg@159: --db | --test-connection | --list-jdbc-properties) franta-hg@82: if [ -f '.$databasesFile.' ]; then franta-hg@82: COMPREPLY=( $( compgen -W " $( cat '.$databasesFile.' ) " -- $cur ) ) franta-hg@82: return 0 franta-hg@82: fi franta-hg@81: ;; franta-hg@81: --formatter) franta-hg@82: if [ -f '.$formattersFile.' ]; then franta-hg@82: COMPREPLY=( $( compgen -W " $( cat '.$formattersFile.' ) " -- $cur ) ) franta-hg@82: else franta-hg@82: COMPREPLY=( $( compgen -W " franta-hg@81: '; franta-hg@81: franta-hg@81: while (<>) { franta-hg@81: if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) { franta-hg@82: print " $1\n"; franta-hg@81: } franta-hg@81: last if (/\/\/\s*bash-completion:options/); franta-hg@81: } franta-hg@81: franta-hg@81: franta-hg@82: print ' " -- $cur ) ); franta-hg@82: fi franta-hg@81: return 0 franta-hg@81: ;; franta-hg@81: esac; franta-hg@81: franta-hg@81: COMPREPLY=( $( compgen -W " franta-hg@81: '; franta-hg@81: franta-hg@81: while (<>) { franta-hg@81: if (/"(.*?)".*? \/\/\s*bash-completion:option/) { franta-hg@81: print " $1\n"; franta-hg@81: } franta-hg@81: } franta-hg@81: franta-hg@81: print ' " -- $cur ) ) franta-hg@81: return 0 franta-hg@81: franta-hg@81: } franta-hg@81: franta-hg@81: complete -F _sql_dk sql-dk franta-hg@81: ';