This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Tarantool -- an efficient key/value data store".
The branch core-help has been updated
via 2750e1d9209141470427f85bf94dc707eeea313d (commit)
from 5fa44c6e6f646ba3fa8e6a377608186110dd64bd (commit)
Summary of changes:
core/tarantool.c | 27 +++++++++++------------
test/box/args.result | 52 ++++++++++++++++++++++++++++++++++++++--------
test/box/args.test | 7 ++++++
third_party/gopt/gopt.c | 41 ++++++++++++++++++++++++++++--------
4 files changed, 95 insertions(+), 32 deletions(-)
commit 2750e1d9209141470427f85bf94dc707eeea313d
Author: Yuriy Vostrikov <[email protected]>
Date: Wed Dec 22 17:06:46 2010 +0300
[core] Align help to fit 80 chars. Add more tests. Fix indening.
diff --git a/core/tarantool.c b/core/tarantool.c
index 05d23e4..456870e 100644
--- a/core/tarantool.c
+++ b/core/tarantool.c
@@ -238,28 +238,27 @@ main(int argc, char **argv)
palloc_init();
const void *opt_def =
- gopt_start(
- gopt_option('g', GOPT_ARG, gopt_shorts(0),
- gopt_longs("cfg-get",
"cfg_get"),
- "=KEY", "return a value from
configuration file described by KEY"),
+ gopt_start(gopt_option('g', GOPT_ARG, gopt_shorts(0),
+ gopt_longs("cfg-get", "cfg_get"),
+ "=KEY", "return a value from
configuration file described by KEY"),
gopt_option('c', GOPT_ARG, gopt_shorts('c'),
- gopt_longs("config"),
- "=FILE", "path to
configuration file (default: " DEFAULT_CFG_FILENAME ")"),
+ gopt_longs("config"),
+ "=FILE", "path to configuration file
(default: " DEFAULT_CFG_FILENAME ")"),
#ifdef STORAGE
gopt_option('C', 0, gopt_shorts(0),
gopt_longs("cat"),
- "=FILE", "cat snapshot file
to stdout in readable format and exit"),
+ "=FILE", "cat snapshot file to stdout in
readable format and exit"),
gopt_option('I', 0, gopt_shorts(0),
- gopt_longs("init-storage",
"init_storage"),
- NULL, "initialize storage
(an empty snapshot file) and exit"),
+ gopt_longs("init-storage",
"init_storage"),
+ NULL, "initialize storage (an empty
snapshot file) and exit"),
#endif
gopt_option('v', 0, gopt_shorts('v'),
gopt_longs("verbose"),
- NULL, "increase verbosity
level in log messages"),
+ NULL, "increase verbosity level in log
messages"),
gopt_option('D', 0, gopt_shorts('D'),
gopt_longs("daemonize"),
- NULL, "redirect input/output
streams to a log file and run as daemon"),
- gopt_option('h', 0, gopt_shorts('h', '?'), gopt_longs("help"),
- NULL, "display this help and
exit"),
+ NULL, "redirect input/output streams to
a log file and run as daemon"),
+ gopt_option('h', 0, gopt_shorts('h', '?'),
gopt_longs("help"),
+ NULL, "display this help and exit"),
gopt_option('V', 0, gopt_shorts('V'),
gopt_longs("version"),
- NULL, "print program version
and exit"));
+ NULL, "print program version and exit"));
void *opt = gopt_sort(&argc, (const char **)argv, opt_def);
diff --git a/test/box/args.result b/test/box/args.result
index 21d9c9b..f743cd7 100644
--- a/test/box/args.result
+++ b/test/box/args.result
@@ -1,25 +1,56 @@
+tarantool_silverbox -Z
+tarantool_silverbox: -Z: unknown option
+
tarantool_silverbox --no-such-option
tarantool_silverbox: --no-such-option: unknown option
+tarantool_silverbox --version --no-such-option
+tarantool_silverbox: --no-such-option: unknown option
+
tarantool_silverbox --help
Tarantool -- an efficient in-memory data store.
Usage: tarantool_silverbox [OPTIONS]
- --cfg-get=KEY return a value from configuration file described
by KEY
- -c, --config=FILE path to configuration file (default:
tarantool.cfg)
- --cat=FILE cat snapshot file to stdout in readable format
and exit
- --init-storage initialize storage (an empty snapshot file) and
exit
- -v, --verbose increase verbosity level in log messages
- -D, --daemonize redirect input/output streams to a log file and
run as daemon
- -h, --help display this help and exit
- -V, --version print program version and exit
+ --cfg-get=KEY return a value from configuration file described by
+ KEY
+ -c, --config=FILE path to configuration file (default: tarantool.cfg)
+ --cat=FILE cat snapshot file to stdout in readable format and
+ exit
+ --init-storage initialize storage (an empty snapshot file) and exit
+ -v, --verbose increase verbosity level in log messages
+ -D, --daemonize redirect input/output streams to a log file and run
as
+ daemon
+ -h, --help display this help and exit
+ -V, --version print program version and exit
+
+Please visit project home page at %launchpad
+to see online documentation, submit bugs or contribute a patch.
+
+tarantool_silverbox -h
+Tarantool -- an efficient in-memory data store.
+Usage: tarantool_silverbox [OPTIONS]
+
+ --cfg-get=KEY return a value from configuration file described by
+ KEY
+ -c, --config=FILE path to configuration file (default: tarantool.cfg)
+ --cat=FILE cat snapshot file to stdout in readable format and
+ exit
+ --init-storage initialize storage (an empty snapshot file) and exit
+ -v, --verbose increase verbosity level in log messages
+ -D, --daemonize redirect input/output streams to a log file and run
as
+ daemon
+ -h, --help display this help and exit
+ -V, --version print program version and exit
-Please visit project home page at http:tarantool
+Please visit project home page at %launchpad
to see online documentation, submit bugs or contribute a patch.
tarantool_silverbox --config
tarantool_silverbox: --config: option requires an option argument
+tarantool_silverbox -c
+tarantool_silverbox: -c: option requires an option argument
+
tarantool_silverbox --config tarantool.cfg
<time> <pid> 0/(null) _ F> PANIC tarantool.c:deamon is running
@@ -29,3 +60,6 @@ tarantool_silverbox --daemonize
tarantool_silverbox --version
1.3.minor-<rev>-<commit>
+tarantool_silverbox -V
+1.3.minor-<rev>-<commit>
+
diff --git a/test/box/args.test b/test/box/args.test
index 9e68045..f5e4056 100644
--- a/test/box/args.test
+++ b/test/box/args.test
@@ -1,12 +1,19 @@
+sys.stdout.push_filter("http://launchpad.net/tarantool", "%launchpad")
sys.stdout.push_filter("(/\S+)+/tarantool", "tarantool")
sys.stdout.push_filter("^\d+\.\d+ \d+", "<time> <pid>")
+server.test_option("-Z")
server.test_option("--no-such-option")
+server.test_option("--version --no-such-option")
server.test_option("--help")
+server.test_option("-h")
server.test_option("--config")
+server.test_option("-c")
server.test_option("--config tarantool.cfg")
server.test_option("--daemonize")
sys.stdout.pop_filter()
sys.stdout.push_filter("(\d\.\d)\.\d-\d+-\S+", "\\1.minor-<rev>-<commit>")
server.test_option("--version")
+server.test_option("-V ")
+sys.stdout.pop_filter()
sys.stdout.pop_filter()
sys.stdout.pop_filter()
diff --git a/third_party/gopt/gopt.c b/third_party/gopt/gopt.c
index 5fa9960..084f1ad 100644
--- a/third_party/gopt/gopt.c
+++ b/third_party/gopt/gopt.c
@@ -268,10 +268,21 @@ void gopt_free( void *vptr_opts ){
void gopt_help(const void *opt_def){
const struct opt_spec_s *opt = opt_def;
- /* -h, --help print help */
- /* ^ this is HELP_MSG_OFFSET */
- const int HELP_MSG_OFFSET = 21;
- while (opt->key) {
+
+ /*
+ * layout:
+ * padding: 2 spaces (" ")
+ * short option: 4 chars, padded with spaces (" " or "-x " or "-x, ")
+ * long option: 20 chars, padded with spaces ("--option ")
+ * help: rest of line: 54
+ * help padding: 25 spaces
+ */
+
+ const int long_opt_width = 18; /* not counting leading "--" */
+ const int help_width = 54;
+ const char *help_padding = " ";
+
+ while (opt->key) {
const char *shorts = opt->shorts;
char has_shorts = 0;
printf(" ");
@@ -288,14 +299,26 @@ void gopt_help(const void *opt_def){
else
printf(" ");
if (opt->help_arg)
- printf("--%s%-*s", *longs, HELP_MSG_OFFSET - strlen(*longs),
+ printf("--%s%-*s", *longs, long_opt_width - strlen(*longs),
opt->help_arg);
else
- printf("--%-*s", HELP_MSG_OFFSET, *longs);
+ printf("--%-*s", long_opt_width, *longs);
}
- if (opt->help)
- puts(opt->help);
- else
+ if (opt->help) {
+ const char *help = opt->help;
+ while (strlen(help) > help_width) {
+ const char *p = help + help_width;
+ while (p > help && *p != ' ')
+ p--;
+ if (p == help)
+ p = help + help_width;
+ printf("%.*s\n", p - help, help);
+ help = p;
+ if (strlen(help))
+ printf(help_padding);
+ }
+ puts(help);
+ } else
puts("");
opt++;
}
--
Tarantool -- an efficient key/value data store
_______________________________________________
Mailing list: https://launchpad.net/~tarantool-developers
Post to : [email protected]
Unsubscribe : https://launchpad.net/~tarantool-developers
More help : https://help.launchpad.net/ListHelp