basic generated help v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 29 Dec 2013 15:28:24 +0100
branchv_0
changeset 967ae30649b30b
parent 95 714e4fac9cd0
child 97 0dcaa48809f2
basic generated help
.hgignore
java/sql-dk/build.xml
java/sql-dk/data/info/globalcode/sql/dk/help.txt
java/sql-dk/help-generator.sh
java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java
java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
scripts/help_generator.pl
     1.1 --- a/.hgignore	Sun Dec 29 14:50:10 2013 +0100
     1.2 +++ b/.hgignore	Sun Dec 29 15:28:24 2013 +0100
     1.3 @@ -7,3 +7,4 @@
     1.4  java/sql-dk/nbproject/private/
     1.5  
     1.6  java/sql-dk/data/info/globalcode/sql/dk/version.txt
     1.7 +java/sql-dk/data/info/globalcode/sql/dk/help.txt
     2.1 --- a/java/sql-dk/build.xml	Sun Dec 29 14:50:10 2013 +0100
     2.2 +++ b/java/sql-dk/build.xml	Sun Dec 29 15:28:24 2013 +0100
     2.3 @@ -92,6 +92,7 @@
     2.4  	
     2.5  	<target name="-pre-compile">
     2.6  		<exec executable="./version-info.sh" output="data/info/globalcode/sql/dk/version.txt"/>
     2.7 +		<exec executable="./help-generator.sh" output="data/info/globalcode/sql/dk/help.txt"/>
     2.8  	</target>
     2.9  	
    2.10  	<target name="-post-jar">
     3.1 --- a/java/sql-dk/data/info/globalcode/sql/dk/help.txt	Sun Dec 29 14:50:10 2013 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,22 +0,0 @@
     3.4 -
     3.5 -Options:
     3.6 -
     3.7 -	--db
     3.8 -	--sql
     3.9 -	--batch
    3.10 -	--data
    3.11 -	--data-named
    3.12 -	--name-prefix
    3.13 -	--name-suffix
    3.14 -	--types
    3.15 -	--formatter
    3.16 -	--help
    3.17 -	--version
    3.18 -	--license
    3.19 -	--list-formatters
    3.20 -	--list-types
    3.21 -	--list-databases
    3.22 -	--test-connection
    3.23 -
    3.24 -(better and localized help will be written…)
    3.25 - 
    3.26 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/java/sql-dk/help-generator.sh	Sun Dec 29 15:28:24 2013 +0100
     4.3 @@ -0,0 +1,7 @@
     4.4 +#!/bin/bash
     4.5 +
     4.6 +cat \
     4.7 +	src/info/globalcode/sql/dk/CLIParser.java \
     4.8 +	src/info/globalcode/sql/dk/CLIStarter.java \
     4.9 +	| ../../scripts/help_generator.pl
    4.10 +
     5.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Sun Dec 29 14:50:10 2013 +0100
     5.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Sun Dec 29 15:28:24 2013 +0100
     5.3 @@ -140,22 +140,22 @@
     5.4  	public static class Tokens {
     5.5  
     5.6  		// bash-completion:options:
     5.7 -		public static final String DB = "--db"; // bash-completion:option
     5.8 -		public static final String SQL = "--sql"; // bash-completion:option
     5.9 -		public static final String BATCH = "--batch"; // bash-completion:option
    5.10 -		public static final String DATA = "--data"; // bash-completion:option
    5.11 -		public static final String DATA_NAMED = "--data-named"; // bash-completion:option
    5.12 -		public static final String NAME_PREFIX = "--name-prefix"; // bash-completion:option
    5.13 -		public static final String NAME_SUFFIX = "--name-suffix"; // bash-completion:option
    5.14 -		public static final String TYPES = "--types"; // bash-completion:option
    5.15 -		public static final String FORMATTER = "--formatter"; // bash-completion:option
    5.16 -		public static final String INFO_HELP = "--help"; // bash-completion:option
    5.17 -		public static final String INFO_VERSION = "--version"; // bash-completion:option
    5.18 -		public static final String INFO_LICENSE = "--license"; // bash-completion:option
    5.19 -		public static final String INFO_FORMATTERS = "--list-formatters"; // bash-completion:option
    5.20 -		public static final String INFO_TYPES = "--list-types"; // bash-completion:option
    5.21 -		public static final String INFO_DATABASES = "--list-databases"; // bash-completion:option
    5.22 -		public static final String INFO_CONNECTION = "--test-connection"; // bash-completion:option
    5.23 +		public static final String DB = "--db"; // bash-completion:option // help: database name
    5.24 +		public static final String SQL = "--sql"; // bash-completion:option // help: SQL query/command
    5.25 +		public static final String BATCH = "--batch"; // bash-completion:option // help: batch mode (no argument)
    5.26 +		public static final String DATA = "--data"; // bash-completion:option // help: list of ordinal parameters
    5.27 +		public static final String DATA_NAMED = "--data-named"; // bash-completion:option // help: list of named parameters
    5.28 +		public static final String NAME_PREFIX = "--name-prefix"; // bash-completion:option // help: parameter name prefix – regular expression
    5.29 +		public static final String NAME_SUFFIX = "--name-suffix"; // bash-completion:option // help: parameter name suffix – regular expression
    5.30 +		public static final String TYPES = "--types"; // bash-completion:option // help: comma separated list of parameter types
    5.31 +		public static final String FORMATTER = "--formatter"; // bash-completion:option // help: name of the output formatter
    5.32 +		public static final String INFO_HELP = "--help"; // bash-completion:option // help: print this help
    5.33 +		public static final String INFO_VERSION = "--version"; // bash-completion:option // help: print version info
    5.34 +		public static final String INFO_LICENSE = "--license"; // bash-completion:option // help: print license
    5.35 +		public static final String INFO_FORMATTERS = "--list-formatters"; // bash-completion:option // help: print list of available formatters
    5.36 +		public static final String INFO_TYPES = "--list-types"; // bash-completion:option // help: print list of supported data types
    5.37 +		public static final String INFO_DATABASES = "--list-databases"; // bash-completion:option // help: print list of configured databases
    5.38 +		public static final String INFO_CONNECTION = "--test-connection"; // bash-completion:option // help: test connection to particular database
    5.39  
    5.40  		private Tokens() {
    5.41  		}
     6.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Sun Dec 29 14:50:10 2013 +0100
     6.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Sun Dec 29 15:28:24 2013 +0100
     6.3 @@ -46,6 +46,7 @@
     6.4   */
     6.5  public class CLIStarter implements ConfigurationProvider {
     6.6  
     6.7 +	// help:exit-codes
     6.8  	public static final int EXIT_SUCCESS = 0; // doc:success
     6.9  	public static final int EXIT_UNEXPECTED_ERROR = 1; // doc:unexpected error (probably bug)
    6.10  	public static final int EXIT_SQL_ERROR = 3; // doc:SQL error
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/scripts/help_generator.pl	Sun Dec 29 15:28:24 2013 +0100
     7.3 @@ -0,0 +1,58 @@
     7.4 +#!/usr/bin/perl
     7.5 +
     7.6 +# SQL-DK
     7.7 +# Copyright © 2013 František Kučera (frantovo.cz)
     7.8 +# 
     7.9 +# This program is free software: you can redistribute it and/or modify
    7.10 +# it under the terms of the GNU General Public License as published by
    7.11 +# the Free Software Foundation, either version 3 of the License, or
    7.12 +# (at your option) any later version.
    7.13 +# 
    7.14 +# This program is distributed in the hope that it will be useful,
    7.15 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.16 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    7.17 +# GNU General Public License for more details.
    7.18 +# 
    7.19 +# You should have received a copy of the GNU General Public License
    7.20 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
    7.21 +
    7.22 +
    7.23 +# Parses Java source code from STDIN and generates simple help
    7.24 +# Input (in this order):
    7.25 +#	info/globalcode/sql/dk/CLIParser.java
    7.26 +#	info/globalcode/sql/dk/CLIStarter.java
    7.27 +
    7.28 +# TODO: localization
    7.29 +
    7.30 +
    7.31 +print 'SQL-DK – and SQL batch client
    7.32 +
    7.33 +Options:
    7.34 +
    7.35 +';
    7.36 +
    7.37 +while (<>) {
    7.38 +	print "	" . sprintf("%-24s", $1) . "$3\n" if (/"(.*?)".*? \/\/\s*bash-completion:option(\s*\/\/\s*help:(.*))?/);
    7.39 +	last if (/\/\/\s*help:exit-codes/);
    7.40 +}
    7.41 +
    7.42 +print '
    7.43 +Examples:
    7.44 +
    7.45 +	sql-dk --db MyDatabase --sql "SELECT * FROM table"
    7.46 +
    7.47 +	sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = ? AND b = ?" --data "abc" "def"
    7.48 +	sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = :paramA AND b = :paramB" --data-named "paramA" "abc" "paramB" "def"
    7.49 +
    7.50 +	sql-dk --db MyDatabase --sql "SELECT * FROM table WHERE a = ? AND b = ?" --types "varchar,integer" --data "abc" "123"
    7.51 +	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"
    7.52 +
    7.53 +Exit codes:
    7.54 +
    7.55 +';
    7.56 +
    7.57 +while (<>) {
    7.58 +	print "	$1 = $2\n" if (/EXIT_.*?=\s*(\d+)\s*;\s*\/\/\s*doc:(.*)/);
    7.59 +}
    7.60 +
    7.61 +print "\n";