basic generated help v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 29 Dec 2013 15:28:24 +0100
branchv_0
changeset 96 7ae30649b30b
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
--- a/.hgignore	Sun Dec 29 14:50:10 2013 +0100
+++ b/.hgignore	Sun Dec 29 15:28:24 2013 +0100
@@ -7,3 +7,4 @@
 java/sql-dk/nbproject/private/
 
 java/sql-dk/data/info/globalcode/sql/dk/version.txt
+java/sql-dk/data/info/globalcode/sql/dk/help.txt
--- a/java/sql-dk/build.xml	Sun Dec 29 14:50:10 2013 +0100
+++ b/java/sql-dk/build.xml	Sun Dec 29 15:28:24 2013 +0100
@@ -92,6 +92,7 @@
 	
 	<target name="-pre-compile">
 		<exec executable="./version-info.sh" output="data/info/globalcode/sql/dk/version.txt"/>
+		<exec executable="./help-generator.sh" output="data/info/globalcode/sql/dk/help.txt"/>
 	</target>
 	
 	<target name="-post-jar">
--- a/java/sql-dk/data/info/globalcode/sql/dk/help.txt	Sun Dec 29 14:50:10 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-
-Options:
-
-	--db
-	--sql
-	--batch
-	--data
-	--data-named
-	--name-prefix
-	--name-suffix
-	--types
-	--formatter
-	--help
-	--version
-	--license
-	--list-formatters
-	--list-types
-	--list-databases
-	--test-connection
-
-(better and localized help will be written…)
- 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/help-generator.sh	Sun Dec 29 15:28:24 2013 +0100
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+cat \
+	src/info/globalcode/sql/dk/CLIParser.java \
+	src/info/globalcode/sql/dk/CLIStarter.java \
+	| ../../scripts/help_generator.pl
+
--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Sun Dec 29 14:50:10 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Sun Dec 29 15:28:24 2013 +0100
@@ -140,22 +140,22 @@
 	public static class Tokens {
 
 		// bash-completion:options:
-		public static final String DB = "--db"; // bash-completion:option
-		public static final String SQL = "--sql"; // bash-completion:option
-		public static final String BATCH = "--batch"; // bash-completion:option
-		public static final String DATA = "--data"; // bash-completion:option
-		public static final String DATA_NAMED = "--data-named"; // bash-completion:option
-		public static final String NAME_PREFIX = "--name-prefix"; // bash-completion:option
-		public static final String NAME_SUFFIX = "--name-suffix"; // bash-completion:option
-		public static final String TYPES = "--types"; // bash-completion:option
-		public static final String FORMATTER = "--formatter"; // bash-completion:option
-		public static final String INFO_HELP = "--help"; // bash-completion:option
-		public static final String INFO_VERSION = "--version"; // bash-completion:option
-		public static final String INFO_LICENSE = "--license"; // bash-completion:option
-		public static final String INFO_FORMATTERS = "--list-formatters"; // bash-completion:option
-		public static final String INFO_TYPES = "--list-types"; // bash-completion:option
-		public static final String INFO_DATABASES = "--list-databases"; // bash-completion:option
-		public static final String INFO_CONNECTION = "--test-connection"; // bash-completion:option
+		public static final String DB = "--db"; // bash-completion:option // help: database name
+		public static final String SQL = "--sql"; // bash-completion:option // help: SQL query/command
+		public static final String BATCH = "--batch"; // bash-completion:option // help: batch mode (no argument)
+		public static final String DATA = "--data"; // bash-completion:option // help: list of ordinal parameters
+		public static final String DATA_NAMED = "--data-named"; // bash-completion:option // help: list of named parameters
+		public static final String NAME_PREFIX = "--name-prefix"; // bash-completion:option // help: parameter name prefix – regular expression
+		public static final String NAME_SUFFIX = "--name-suffix"; // bash-completion:option // help: parameter name suffix – regular expression
+		public static final String TYPES = "--types"; // bash-completion:option // help: comma separated list of parameter types
+		public static final String FORMATTER = "--formatter"; // bash-completion:option // help: name of the output formatter
+		public static final String INFO_HELP = "--help"; // bash-completion:option // help: print this help
+		public static final String INFO_VERSION = "--version"; // bash-completion:option // help: print version info
+		public static final String INFO_LICENSE = "--license"; // bash-completion:option // help: print license
+		public static final String INFO_FORMATTERS = "--list-formatters"; // bash-completion:option // help: print list of available formatters
+		public static final String INFO_TYPES = "--list-types"; // bash-completion:option // help: print list of supported data types
+		public static final String INFO_DATABASES = "--list-databases"; // bash-completion:option // help: print list of configured databases
+		public static final String INFO_CONNECTION = "--test-connection"; // bash-completion:option // help: test connection to particular database
 
 		private Tokens() {
 		}
--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Sun Dec 29 14:50:10 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Sun Dec 29 15:28:24 2013 +0100
@@ -46,6 +46,7 @@
  */
 public class CLIStarter implements ConfigurationProvider {
 
+	// help:exit-codes
 	public static final int EXIT_SUCCESS = 0; // doc:success
 	public static final int EXIT_UNEXPECTED_ERROR = 1; // doc:unexpected error (probably bug)
 	public static final int EXIT_SQL_ERROR = 3; // doc:SQL error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/help_generator.pl	Sun Dec 29 15:28:24 2013 +0100
@@ -0,0 +1,58 @@
+#!/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 – and 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";