* ruby.c (usage): wrap description lines if options are too long.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-11-23 08:31:57 +00:00
Родитель 38a1bcb056
Коммит 48df345894
3 изменённых файлов: 22 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Fri Nov 23 17:31:54 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (usage): wrap description lines if options are too long.
Fri Nov 23 11:13:46 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/ruby/test_rubyoptions.rb (TestRubyOptions#test_usage2): refine

21
ruby.c
Просмотреть файл

@ -172,10 +172,10 @@ usage(const char *name, int help)
};
static const struct message help_msg[] = {
M("--copyright", "", "print the copyright"),
M("--enable=feature[,...]", "", "enable features"),
M("--disable=feature[,...]", "", "disable features"),
M("--internal-encoding=encoding", "", "specify the default internal character encoding"),
M("--external-encoding=encoding", "", "specify the default external character encoding"),
M("--enable=feature[,...]", ", --disable=feature[,...]",
"enable or disable features"),
M("--internal-encoding=encoding", ", --external-encoding=encoding",
"specify the default internal and external character encoding"),
M("--version", "", "print the version"),
M("--help", "", "show this message, -h for short message"),
};
@ -183,10 +183,15 @@ usage(const char *name, int help)
M("gems", "", "rubygems (default: "DEFAULT_RUBYGEMS_ENABLED")"),
M("rubyopt", "", "RUBYOPT environment variable (default: enabled)"),
};
int i, w = help ? 32 : 16, num = numberof(usage_msg) - (help ? 1 : 0);
#define SHOW(m) printf(" %.*s%-*.*s%s\n", (m).namelen-1, (m).str, \
w - (m).namelen + 1, (help ? (m).secondlen-1 : 0), (m).str + (m).namelen, \
(m).str + (m).namelen + (m).secondlen)
int i, w = 16, num = numberof(usage_msg) - (help ? 1 : 0);
#define SHOW(m) do { \
int wrap = help && (m).namelen + (m).secondlen - 2 > w; \
printf(" %.*s%-*.*s%-*s%s\n", (m).namelen-1, (m).str, \
(wrap ? 0 : w - (m).namelen + 1), \
(help ? (m).secondlen-1 : 0), (m).str + (m).namelen, \
(wrap ? w + 3 : 0), (wrap ? "\n" : ""), \
(m).str + (m).namelen + (m).secondlen); \
} while (0)
printf("Usage: %s [switches] [--] [programfile] [arguments]\n", name);
for (i = 0; i < num; ++i)

Просмотреть файл

@ -40,6 +40,11 @@ class TestRubyOptions < Test::Unit::TestCase
assert_equal([], longer)
assert_equal([], e)
end
assert_in_out_err(%w(--help)) do |r, e|
longer = r[1..-1].select {|x| x.size > 80}
assert_equal([], longer)
assert_equal([], e)
end
end
def test_option_variables