INFO: The new Git default branch name is "main". Details here: https://about.gitlab.com/blog/2021/03/10/new-git-default-branch-name/

Commit ad1398dd authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Added descriptions in --help

parent 7e929e61
......@@ -2,7 +2,7 @@
`mysql_printf` is a mysql client command line tool for formatting query results by *printf-like* string format.
The *printf-like* strings can containing conversion specifiers `%s` to customize the indentation and position of the column values in the query results.
The *printf-like* strings can contain conversion specifiers `%s` to customize the indentation and position of the column values in the query results.
You can arrange the values of a single query row as a list of Delimiter-Separated-Values (i.e. CSV, _comma separated values_), or formatting them in a more complex way, for instance arranging the values of a single query row result in several customized lines.
......@@ -132,3 +132,4 @@ Mail bug reports and suggestions to *matteo.quintiliani [at] ingv.it*
## License
Software is open-source and released under GNU Library General Public License.
\ No newline at end of file
......@@ -172,7 +172,7 @@ int main(int argc, char **argv)
} else if(params.str_sql) {
query = strdup(params.str_sql);
} else {
fprintf(stderr, "Neither filesql nor strsql are defined!\n");
fprintf(stderr, "Neither argument <sqlfile> nor <sqlstr> are defined!\n");
return -1;
}
......@@ -641,11 +641,11 @@ int mysql_printf_getopt_long(int argc, char **argv, MYSQL_FORMAT_PARAMS *params)
{"dbconfname", required_argument, NULL, 'D'},
#endif
{"strformat", required_argument, NULL, 'F'},
{"fileformat", required_argument, NULL, 'f'},
{"fmtstr", required_argument, NULL, 'F'},
{"fmtfile", required_argument, NULL, 'f'},
{"delimiter", required_argument, NULL, 'e'},
{"strsql", required_argument, NULL, 'S'},
{"filesql", required_argument, NULL, 's'},
{"sqlstr", required_argument, NULL, 'S'},
{"sqlfile", required_argument, NULL, 's'},
{"outputdir", required_argument, NULL, 'o'},
/* Following are flags */
......@@ -828,8 +828,8 @@ int mysql_printf_getopt_long(int argc, char **argv, MYSQL_FORMAT_PARAMS *params)
void mysql_printf_author_support() {
printf("\
Matteo Quintiliani - Istituto Nazionale di Geofisica e Vulcanologia - Italy\n\
Mail bug reports and suggestions to <%s>.\n",
Matteo Quintiliani - Istituto Nazionale di Geofisica e Vulcanologia - Italy\n\
Mail bug reports and suggestions to <%s>.\n",
STR_NULL(PACKAGE_BUGREPORT)
);
}
......@@ -837,23 +837,27 @@ void mysql_printf_author_support() {
void mysql_printf_version() {
printf("\
%s %s, executes query(ies) and format the result as text\n",
%s %s ",
STR_NULL(PACKAGE_NAME), STR_NULL(PACKAGE_VERSION)
);
mysql_printf_supports();
printf("\n\
A mysql client command line tool for formatting query results\n\
by printf-like string format\n");
}
void mysql_printf_supports() {
printf("\
Enabled features: libconfig ");
printf("(enabled features: libconfig ");
#ifdef HAVE_LIBCONFIG
printf("YES");
#else
printf("NO");
#endif
printf(".\n");
printf(")\n");
}
......@@ -861,126 +865,107 @@ void mysql_printf_usage(struct option long_options[]) {
mysql_printf_version();
printf("\
\n\
Usage: %s\n\
{ -S str_sql | -s filename_sql }\n\
{ -F str_format | -f filename_format | [ -e delimiter ] }\n",
STR_NULL(PACKAGE_NAME));
printf("\n\
Main usage in short: %s\n",
STR_NULL(PACKAGE_NAME));
#ifdef HAVE_LIBCONFIG
printf("\
{\n\
[ -C fileconf ] [ -D dbconfname ]\n\
|\n\
-h hostname -d dbname [ -u username ] [ -p password ] [ -P dbport ]\n\
}\n");
(\n\
[ -C fileconf ] [ -D dbconfname ]\n\
|\n\
-h hostname -d dbname [ -u username ] [ -p password ] [ -P dbport ]\n\
)\n");
#else
printf("\
-h hostname -d dbname [ -u username ] [ -p password ] [ -P dbport ]\n");
-h hostname -d dbname [ -u username ] [ -p password ] [ -P dbport ]\n");
#endif
printf("\
[ -c ] [ -m ] [ -o <outputdir> ]\n\
\n\
%s executes query(ies) and format the result as text.\n\
Default text output format is DSV (Delimiter-Separated-Values).\n\
Custom output format can be defined by a printf-string-format which\n\
contains %%s for indenting and positioning fields of query result.\n\
The number of %%s within the string has to be equal to the number\n\
of attributes of the query result. One less for option -m.\n\
mysql_printf handles all attribute values as strings, you have to\n\
delegate SQL for mathematic computation or string concatenations.\n\
\n", STR_NULL(PACKAGE_NAME));
( -S SqlQueryString | -s SqlQueryFileName )\n\
( -F PrintfFormatString | -f PrintfFormatFileName | -e delimiter )\n");
printf("\
The following examples should explain better the possible usages.\n\
\n\
Example of output formats for 14 attributes is:\n\
%%-5s %%2s %%1s%%s %%2s %%7s%%1s%%3s %%7s%%1s %%6s %%s%%s %%-s\n\
\n");
printf("\
Example of a query:\n\
\"SELECT name, age, sex FROM people;\"\n\
and its possible output format:\n\
\"%%-5s %%2s %%1s\"\n\
\n");
printf("\
Example of command line:\n\
%s -h host -d dbname -u user -p pass \\\n\
-S \"SELECT name, age, sex FROM people;\" \\\n\
-F \"%%-5s %%2s %%1s\"\n\n\
%s -h host -d dbname -u user -p pass \\\n\
-S \"SELECT name, age, sex FROM people;\" \\\n\
-e ','\n\n\
%s -h host -d dbname -u user -p pass \\\n\
-S \"SELECT CONCAT(age, '.txt'), name, sex, 'nice' FROM nice_people;\" \\\n\
-m\n\
%s -h host -d dbname -u user -p pass \\\n\
-S \"SELECT CONCAT(age, '.txt'), name, sex, 'nasty' FROM nasty_people;\" \\\n\
-a -m\n\
The two last commands create several files, one for each age,\n\
containing all people with the same age.\n\
\n",
STR_NULL(PACKAGE_NAME), STR_NULL(PACKAGE_NAME),
STR_NULL(PACKAGE_NAME), STR_NULL(PACKAGE_NAME));
[ -c ] [ -a ] [ -m ] [ -o <outputdir> ]\n");
printf("\n\
mysql_printf is a mysql client command line tool for formatting query results\n\
by printf-like string format. The printf-like strings can contain conversion\n\
specifiers %%s to customize the indentation and position of the column values\n\
in the query results.\n\
You can arrange the values of a single query row as a list of Delimiter\n\
Separated Values (i.e. CSV, comma separated values), or formatting them in a\n\
more complex way, for instance arranging the values of a single query row\n\
result in several customized lines.\n\
mysql_printf can be very useful to generate custom text files from database\n\
information.\n\
");
printf("\
%s --help | -H\n\
Print this help.\n\
\n", STR_NULL(PACKAGE_NAME));
Without defining a printf-like string format, the default text output format is\n\
a list of delimiter-separated-values where delimiter is ';', but you can change\n\
with whatever character you want.\n\
mysql_printf handles all attribute values as strings, in fact it can accept\n\
only the printf conversion specifiers %%s. You can rely on powerful MySQL\n\
functions for pre-processing output fields format, mathematic computation or\n\
string concatenations.\n\
The conversion specifiers %%s within the printf-like strings have to be as many\n\
as the fields of the query result, except when using the option -m (see later).\n\
mysql_printf is also able to process the escape sequence, such as \\n, \\t, etc.\n\
\n");
printf("\
Main arguments:\n\
-S, --strsql=STRING SQL query string.\n\
-s, --filesql=FILE File name contains SQL query string.\n\
-F, --strformat=STRING Output format string.\n\
-f, --fileformat=FILE File name contains output format string.\n\
-e, --delimiter=C Delimiter character between fields (default '%c').\n\
-o, --ouputdir=DIR Output directory for output files.\n",
Main arguments:\n\
-S, --sqlstr=STRING SQL Query String.\n\
-s, --sqlfile=FILE Filename containing SQL Query String.\n\
\n\
-F, --fmtstr=STRING printf-like format string.\n\
-f, --fmtfile=FILE File name containing printf-like format string.\n\
-e, --delimiter=C Delimiter character between fields (default '%c').\n",
DELIMITER_CHAR_DEFAULT);
#ifdef HAVE_LIBCONFIG
printf("\
\n\
Arguments for libconfig:\n\
-C, --fileconf=FILE DB configuration file (default %s).\n\
-D, --dbconfname=NAME DB name to use from configuration file.\n",
\n\
Arguments for libconfig:\n\
-C, --fileconf=FILE DB configuration file (default %s).\n\
-D, --dbconfname=NAME DB name to use from configuration file.\n",
config_filename_default);
#endif
printf("\
\n\
Arguments for MySQL:\n\
-h, --host=name Connect to MySQL host.\n\
-u, --user=name MySQL User for login.\n\
-p, --password=name Password to use when connecting to server.\n\
-d, --database=name Data base name to connect.\n\
-P, --port=# Port number to use for connection or 0 for default.\n");
Arguments for MySQL:\n\
-h, --host=name Connect to MySQL host.\n\
-u, --user=name MySQL User for login.\n\
-p, --password=name Password to use when connecting to server.\n\
-d, --database=name Data base name to connect.\n\
-P, --port=# Port number to use for connection or 0 for default.\n");
printf("\
\n\
Advanced arguments:\n\
-m, --multifiles Create several files instead of formatting\n\
everything to the standard output.\n\
Each formatting of a single row of the query result\n\
will be redirected in a distinct file.\n\
The first attribute of the query result will\n\
assign the output file name.\n\
The output format string must contain one %%s less\n\
than number of attributes of query result.\n\
-a, --appendfile With -m, each formatting of a row is appended\n\
to the output file.\n"
\n\
Advanced arguments:\n\
-m, --multifiles Create several files instead of formatting\n\
everything to the standard output.\n\
Each formatting of a single row of the query result\n\
will be redirected in a distinct file.\n\
The first attribute of the query result will\n\
assign the output file name.\n\
The output format string must contain one %%s less\n\
than number of attributes of query result.\n\
-a, --appendfile With -m, each formatting of a row is appended\n\
to the output file.\n\
-o, --ouputdir=DIR Output directory for output files.\n"
);
printf("\
\n\
Other arguments:\n\
-c, --addcomment Add comment in output, suffix #.\n\
-V, --version Print tool version.\n\
-H, --help Print this help.\n\
\n");
\n\
Other arguments:\n\
-c, --addcomment Add comment in output, prefix # as first character.\n\
-V, --version Print tool version.\n\
-H, --help Print this help.\n\
\n");
mysql_printf_author_support();
......@@ -992,19 +977,19 @@ int mysql_printf_check_params(MYSQL_FORMAT_PARAMS *params) {
if(params->filename_sql == NULL && params->str_sql == NULL) {
ret = -1;
fprintf(stderr, "<filesql> xor <strsql> is required!\n");
fprintf(stderr, "Argument <sqlfile> xor <sqlstr> is required!\n");
/*
} else if(params->filename_format == NULL && params->str_format == NULL) {
ret = -1;
fprintf(stderr, "<fileformat> xor <str_format> is required!\n");
fprintf(stderr, "<fmtfile> xor <str_format> is required!\n");
*/
} else if(params->filename_sql != NULL && params->str_sql != NULL) {
ret = -1;
fprintf(stderr, "Only <filesql> or <strsql> can be defined, not together!\n");
fprintf(stderr, "Only one argument between <sqlfile> or <sqlstr> can be defined, not together!\n");
/*
} else if(params->filename_format != NULL && params->str_format != NULL) {
ret = -1;
fprintf(stderr, "<fileformat> or <str_format> can be define, not together!\n");
fprintf(stderr, "<fmtfile> or <str_format> can be define, not together!\n");
*/
} else if(params->outputdir != NULL) {
if(!mysql_printf_dir_exists(params->outputdir)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment