diff --git a/core/tarantool.c b/core/tarantool.c index 05d23e47339c364a3e542eb1d7538d99e5194e3c..456870e06abc72ad6da5b623a1230813e668bc16 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 21d9c9bc259593b1a167caf4f1db75be87fe571b..f743cd71c1eb4ee0fae2c31dc6217db61afed47e 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 9e68045b027126f355bccbca934c74dfc26e5294..f5e405665f86b067e7a90ae3c5f8ff9fd4898173 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 5fa9960043fe4adfb003ddba203c6022dfd0f777..084f1ad807139bc9c368ce5dff85d9c0a55c3dba 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++; }