After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 336089 - goption should have a print_help() method
goption should have a print_help() method
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
: 338242 (view as bug list)
Depends on:
Blocks: 336090
 
 
Reported: 2006-03-26 14:40 UTC by Dominic Lachowicz
Modified: 2011-02-18 16:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
a patch along these lines would be fine (3.54 KB, patch)
2006-03-26 15:15 UTC, Dominic Lachowicz
none Details | Review
Patch that only does --help-all (2.34 KB, patch)
2006-03-26 18:38 UTC, Dominic Lachowicz
none Details | Review

Description Dominic Lachowicz 2006-03-26 14:40:04 UTC
Having the equivalent of poptPrintHelp() would be useful for printing errors.
Comment 1 Dominic Lachowicz 2006-03-26 15:15:37 UTC
Created attachment 62045 [details] [review]
a patch along these lines would be fine

Kinda cruddy patch - basically, it just exports the internal print_help() method under a new name.
Comment 2 Matthias Clasen 2006-03-26 16:41:26 UTC
Do you need the full print_help() api, or would a simpler 
g_option_context_print_help (GOptionContext *context);
that does the equivalent of --help-all be enough ? 
Comment 3 Dominic Lachowicz 2006-03-26 18:38:13 UTC
Created attachment 62058 [details] [review]
Patch that only does --help-all

Having the equivalent of --help-all would probably be good enough.
Comment 4 Christian Persch 2006-03-26 23:13:33 UTC
I'm of the opposite opinion actually: IMHO the equivalent of --help is enough (the output of --help-all will be too large e.g. when using gnome-program so you don't see the relevant options in all the libraries' options).
Comment 5 Matthias Clasen 2006-03-27 17:24:52 UTC
I have my doubts on this. Dom mentioned two usecases on irc:

1) automatic help support has been disabled, and you want to implement
   --help yourself
2) print out help if you meet an invalid argument

But for 1), one could just say "Why ?", and for 2), it would probably
better to not dump the whole screenful of --help-all output to the screen,
but rather just a more narrow explanation of the possible values for the
one invalid argument.
Comment 6 Matthias Clasen 2006-03-27 17:25:30 UTC
Leaving this bug open for now, to see if there is broad demand.
Comment 7 Behdad Esfahbod 2006-03-27 17:50:21 UTC
One reason I may want to disable automatic help is that in a simple program with a few options, by default glib separates --help into its own "Help Options" group, while the rest go into "Application Options".   That doesn't make much sense.  That's another problem though.
Comment 8 Matthias Clasen 2006-03-27 18:42:46 UTC
I would propose that thats simply a bug, and the --help option should be included
with "Application Options" if there are no groups. Every GTK+ app has at least
a "GTK+ options" group though...
Comment 9 Joost Remijn 2006-03-28 20:40:33 UTC
I would like this too but i have an additional request/idea.

Would it be possible to add non-option arguments to the parser. It's not that important for argument handling (would be nice though) but especially for the help output. Most command line tools print the non-option arguments in the help output too. 

Now i should probably open another feature request but this is exactly the reason i came here because i do the argument handling after the parse step and when i miss the filename argument to my program i'd like to print out the help. But it would be even better if this help included the arguments which the user should still provide.
Comment 10 Matthias Clasen 2006-03-28 20:46:45 UTC
Joost, that is what the parameter_string is for. If you  make it "FILES..."
you get 

Usage:
   foo [OPTIONS...] FILES...
Comment 11 Joost Remijn 2006-03-28 21:37:54 UTC
Thanks Matthias. I didn't catch that in the docs, my fault. 

This does however make a strong case for adding this print_help() function available. If the user doesn't give this argument i'd like to print out the help.

I don't know the difference between the --help and --help-all options (there is no difference in my simple program) but i would prefer something which is equal to what is printed when there is an error in the options.
Comment 12 Behdad Esfahbod 2006-04-12 18:13:41 UTC
*** Bug 338242 has been marked as a duplicate of this bug. ***
Comment 13 Martyn Russell 2006-06-08 15:54:53 UTC
Matthias, this would be really cool if we could have it :) 

One of the most common use cases for me are test cases where I test varying aspects of an API. In this case I tend to use an argument for different parts of the API I will test. Using no arguments usually to shows the "use --help for more information..." and I would rather it just printed the help with no arguments.

As far as the --help or --help-all print out is concerned, I think it should print just the --help statement and not the --help-all statement. How many times do you need to know about 3rd party options in comparison to this app's options?

You could remedy the --help-all by simply including it in the normal help statement, e.g.:

Help Options:
  -?, --help                       Show help options
      --help-all                   Show help for 3rd party software


Or something to that effect, it is only one line instead of ALL the lines the user would see if we defaulted to --help-all.
Comment 14 Andrew W. Nosenko 2006-06-09 10:34:23 UTC
Yet another use-case: nearly to all software written by me uses '-h' option for help.  With current g_option_* API it is impossible to simulate such behavior.

Posibility to add some strings before "Usage: prog..." (e.g. version and copyright), and some strings after all options (e.g. 2-3 lines long explanation of the iteraction of some options) is very usefull too.  But it ts impossible also (at least with glib-2.8.6).

About '--help' vs. '--help-all': Just need to provide two functions: one for '--help' and one for '--help-all'.  This will put out flame about apples vs. oranges.

Also: for avoiding flame stdout vs. stderr, this functions should return string and it will be  user's/caller's responsiblity to use stream appropriate for his task.
Comment 15 Matthias Clasen 2006-06-09 13:35:10 UTC
> Posibility to add some strings before "Usage: prog..." (e.g. version and
> copyright), and some strings after all options (e.g. 2-3 lines long explanation
> of the iteraction of some options) is very usefull too.  But it ts impossible
> also (at least with glib-2.8.6).


This has been added in 2.11
Comment 16 Behdad Esfahbod 2006-06-09 19:26:01 UTC
I pretty much agree that there should be a way to bind -h to --help.

As for stdout vs. stderr, flexibility is indeed needed, as according to GNU conding standards, --help output should go to stdout, while if that's triggered by an error, it should go to stderr.
Comment 17 Matthias Clasen 2007-04-11 13:16:54 UTC
So, one way to make everybody happy (except for those who want simple apis) would be to go back to Dom's initial patch that just exports print_help(), and add a
boolean print_to_stderr argument. 
Comment 18 Martyn Russell 2007-04-11 13:30:26 UTC
Matthias, that sounds good enough to me :)
Comment 19 Joost Remijn 2007-04-11 17:49:57 UTC
Sounds good to me as well.
Comment 20 Matthias Clasen 2007-04-25 03:58:07 UTC
2007-04-24  Matthias Clasen  <mclasen@redhat.com>

        * glib/glib.symbols:
        * glib/goption.h:
        * glib/goption.c (g_option_context_get_help): New function to
        get the formatted help string.  (#336089, Dom Lachowicz)

Comment 21 Stefan Sauer (gstreamer, gtkdoc dev) 2007-07-19 06:25:21 UTC
Matthis, which glib version have the patch (comment #20). I am missing poptPrintUsage(context,stdout,0); equivalent in GOption. It looks like this is what has been added.
Comment 22 Matthias Clasen 2007-07-19 13:32:34 UTC
it is in 2.13