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