scripts/help_generator.pl
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Oct 2019 21:43:08 +0200
branchv_0
changeset 250 aae5009bd0af
parent 200 2e351d7c26c4
permissions -rwxr-xr-x
fix license version: GNU GPLv3

#!/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, version 3 of the License.
# 
# 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("%-32s", $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";