GNOME Bugzilla – Bug 504142
Do not show empty groups in --help output
Last modified: 2007-12-24 11:13:41 UTC
g_option_context_get_help() prints all groups in the context, even if a group has only hidden or G_OPTIONA_FLAG_IN_MAIN entries. Attached patch makes --help and --help-all print only groups which have some options displayed with --help-all.
Created attachment 101149 [details] [review] patch
Created attachment 101204 [details] [review] [1/1] Do not show empty groups in --help output. Initial patch from Yevgen Muntyan. (#504142) * glib/goption.c: Do not show empty groups in --help output. * glib/tests/Makefile.am: Add option-context.c * glib/tests/option-context.c: Test skipping of empty groups. --- ChangeLog | 9 +++ glib/goption.c | 83 +++++++++++++++++----- glib/tests/Makefile.am | 4 + glib/tests/option-context.c | 162 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 241 insertions(+), 17 deletions(-)
Seems the initial patch didn't catch all cases where empty groups where shown. This patch tries to do better, and also adds an unit-test. Problems: The behaviour of --help-foo, where "foo" is an empty group is kind of unclear. With that patch no entry for "--help-foo" is generated on "--help", but "--help-foo" still is accepted - without creating any output for "foo". Is that ok? Or should "--help-foo" be rejected? Or should glib print some additional information?
(In reply to comment #3) > Problems: The behaviour of --help-foo, where "foo" is an empty group is kind of > unclear. With that patch no entry for "--help-foo" is generated on "--help", > but "--help-foo" still is accepted - without creating any output for "foo". Is > that ok? Or should "--help-foo" be rejected? Or should glib print some > additional information? With my patch --help-foo did print non-hidden options I believe, which is good (though the --help-foo option itself becomes hidden, which is good too). But I did miss the case when all options are hidden. I'd think --help-foo shouldn't be accepted at all if all the options in group "foo" are hidden (with G_OPTION_FLAG_HIDDEN, not just G_OPTION_FLAG_IN_MAIN). And same thing for empty groups.
I can hardly get excited about the treatment of empty groups, but the patch looks ok to me.
2007-12-22 Mathias Hasselmann <mathias@openismus.com> Do not show empty groups in --help output. Initial patch from Yevgen Muntyan. (#504142) * glib/goption.c: Do not show empty groups in --help output. * glib/tests/Makefile.am: Add option-context.c * glib/tests/option-context.c: Test skipping of empty groups.