null+****@clear*****
null+****@clear*****
2010年 6月 11日 (金) 14:34:25 JST
Nobuyoshi Nakada 2010-06-11 05:34:25 +0000 (Fri, 11 Jun 2010)
New Revision: 1e9765eecad8f3d08605ef7b64cd126067a5d3f0
Log:
emits usage to stdout and exits gracefully. #340
Added files:
test/unit/gqtp/test-option-help.rb
Modified files:
src/groonga.c
test/unit/gqtp/Makefile.am
Modified: src/groonga.c (+9 -5)
===================================================================
--- src/groonga.c 2010-06-11 02:01:49 +0000 (47300e0)
+++ src/groonga.c 2010-06-11 05:34:25 +0000 (e85d5a4)
@@ -59,10 +59,10 @@ static uint32_t default_max_nfthreads = DEFAULT_MAX_NFTHREADS;
static const char *pidfile_path;
static void
-usage(void)
+usage(FILE *output)
{
gethostname(hostname, HOST_NAME_MAX);
- fprintf(stderr,
+ fprintf(output,
"Usage: groonga [options...] [dest]\n"
"options:\n"
" -n: create new database\n"
@@ -1624,7 +1624,8 @@ enum {
mode_daemon,
mode_server,
mode_usage,
- mode_version
+ mode_version,
+ mode_error
};
#define MODE_MASK 0x007f
@@ -1697,7 +1698,7 @@ main(int argc, char **argv)
}
strcpy(listen_address, "0.0.0.0");
i = grn_str_getopt(argc, argv, opts, &mode);
- if (i < 0) { mode = mode_usage; }
+ if (i < 0) { mode = mode_error; }
if (portstr) { port = atoi(portstr); }
if (encstr) {
switch (*encstr) {
@@ -1809,8 +1810,11 @@ main(int argc, char **argv)
case mode_version :
show_version(); r = 0;
break;
+ case mode_usage :
+ usage(stdout); r = 0;
+ break;
default :
- usage(); r = -1;
+ usage(stderr); r = -1;
break;
}
grn_fin();
Modified: test/unit/gqtp/Makefile.am (+1 -0)
===================================================================
--- test/unit/gqtp/Makefile.am 2010-06-11 02:01:49 +0000 (76e7a8a)
+++ test/unit/gqtp/Makefile.am 2010-06-11 05:34:25 +0000 (d3285bd)
@@ -2,4 +2,5 @@ EXTRA_DIST = \
test-cache.rb \
test-restore.rb \
test-load.rb \
+ test-option-help.rb \
test-option-pid-file.rb
Added: test/unit/gqtp/test-option-help.rb (+34 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/gqtp/test-option-help.rb 2010-06-11 05:34:25 +0000 (410a106)
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2010 Nobuyoshi Nakada <nakad****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+class OptionHelpTest < Test::Unit::TestCase
+ include GroongaTestUtils
+
+ # def setup
+ # setup_database_path
+ # end
+
+ # def teardown
+ # teardown_database_path
+ # end
+
+ def test_help_option
+ usage = run_groonga("--help")
+ assert_predicate($?, :success?)
+ assert_match(/\AUsage: groonga \[options\.\.\.\] \[dest\]$/, usage)
+ end
+end