#!/usr/bin/perl
# SQL-DK
# Copyright © 2013 František Kučera (frantovo.cz)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Parses Java source code from STDIN and generates simple help
# Input (in this order):
# info/globalcode/sql/dk/CLIParser.java
# info/globalcode/sql/dk/CLIStarter.java
# TODO: localization
print 'SQL-DK – an SQL batch client
Options:
';
while (<>) {
print " " . sprintf("%-24s", $1) . "$3\n" if (/"(.*?)".*? \/\/\s*bash-completion:option(\s*\/\/\s*help:(.*))?/);
last if (/\/\/\s*help:exit-codes/);
}
print '
Examples:
sql-dk --db MyDatabase --sql "SELECT * FROM table"
sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = ? AND b = ?" --data "abc" "def"
sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = :paramA AND b = :paramB" --data-named "paramA" "abc" "paramB" "def"
sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = ? AND b = ?" --types "varchar,integer" --data "abc" "123"
sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = :paramA AND b = :paramB" --types "paramA:varchar,paramB:integer" --data-named "paramA" "abc" "paramB" "123"
Exit codes:
';
while (<>) {
print " $1 = $2\n" if (/EXIT_.*?=\s*(\d+)\s*;\s*\/\/\s*doc:(.*)/);
}
print "\n";