scripts/help_generator.pl
author František Kučera <franta-hg@frantovo.cz>
Tue, 26 Feb 2019 15:57:49 +0100
branchv_0
changeset 233 0fb3b92e01c5
parent 200 2e351d7c26c4
child 250 aae5009bd0af
permissions -rwxr-xr-x
XML array hack
franta-hg@96
     1
#!/usr/bin/perl
franta-hg@96
     2
franta-hg@96
     3
# SQL-DK
franta-hg@96
     4
# Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@96
     5
# 
franta-hg@96
     6
# This program is free software: you can redistribute it and/or modify
franta-hg@96
     7
# it under the terms of the GNU General Public License as published by
franta-hg@96
     8
# the Free Software Foundation, either version 3 of the License, or
franta-hg@96
     9
# (at your option) any later version.
franta-hg@96
    10
# 
franta-hg@96
    11
# This program is distributed in the hope that it will be useful,
franta-hg@96
    12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@96
    13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@96
    14
# GNU General Public License for more details.
franta-hg@96
    15
# 
franta-hg@96
    16
# You should have received a copy of the GNU General Public License
franta-hg@96
    17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@96
    18
franta-hg@96
    19
franta-hg@96
    20
# Parses Java source code from STDIN and generates simple help
franta-hg@96
    21
# Input (in this order):
franta-hg@96
    22
#	info/globalcode/sql/dk/CLIParser.java
franta-hg@96
    23
#	info/globalcode/sql/dk/CLIStarter.java
franta-hg@96
    24
franta-hg@96
    25
# TODO: localization
franta-hg@96
    26
franta-hg@96
    27
franta-hg@100
    28
print 'SQL-DK – an SQL batch client
franta-hg@96
    29
franta-hg@96
    30
Options:
franta-hg@96
    31
franta-hg@96
    32
';
franta-hg@96
    33
franta-hg@96
    34
while (<>) {
franta-hg@200
    35
	print "	" . sprintf("%-32s", $1) . "$3\n" if (/"(.*?)".*? \/\/\s*bash-completion:option(\s*\/\/\s*help:(.*))?/);
franta-hg@96
    36
	last if (/\/\/\s*help:exit-codes/);
franta-hg@96
    37
}
franta-hg@96
    38
franta-hg@96
    39
print '
franta-hg@96
    40
Examples:
franta-hg@96
    41
franta-hg@96
    42
	sql-dk --db MyDatabase --sql "SELECT * FROM table"
franta-hg@96
    43
franta-hg@96
    44
	sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = ? AND b = ?" --data "abc" "def"
franta-hg@96
    45
	sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = :paramA AND b = :paramB" --data-named "paramA" "abc" "paramB" "def"
franta-hg@96
    46
franta-hg@96
    47
	sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = ? AND b = ?" --types "varchar,integer" --data "abc" "123"
franta-hg@96
    48
	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"
franta-hg@96
    49
franta-hg@96
    50
Exit codes:
franta-hg@96
    51
franta-hg@96
    52
';
franta-hg@96
    53
franta-hg@96
    54
while (<>) {
franta-hg@96
    55
	print "	$1 = $2\n" if (/EXIT_.*?=\s*(\d+)\s*;\s*\/\/\s*doc:(.*)/);
franta-hg@96
    56
}
franta-hg@96
    57
franta-hg@96
    58
print "\n";