D. Hugh Redelmeier wrote:
In help.c cmd_usage():
- make sure that cmd_usage does not call gdb if gdb isn't initialized
(in trying to give -h help for an unrecognized command)
- add a flag MUST_HELP to cmd_usage to specify that if help isn't
found a diagnostic should be printed. This used to be the case if
the command calling cmd_usage was help but not if -h called it.
- this command still unconditionally uses less(1) for anything but a
synopsis. This should be changed.
In main.c, the long_options array:
- use the name "required_argument" in place of the magic number 1.
- make --help a synonym of 'h'
- specify that --help has an optional_argument.
In main.c main():
- in the call of getopt_long: add another ':' for -h. This means
that the argument is optional. This, in turn, means that the switch
default no longer handles -h at the end of an argument list.
- I added code to detect and report an unhandled long option. It is
easy to get the long_option table out of sync with the handlers.
Mostly this involves adding "else" a lot of places in case 0.
- ditch the code to implement --help since it is now handled by the
code for -h
- ditch the code to implement -h in the switch default since it is now
handled in case 'h'
- the case 'h' code now has to handle the fact that the -h / --help
argument is optional.
- removed -H flag which wasn't documented and is now redundant.
OK, this all looks pretty reasonable. I haven't played with it
yet because the patch doesn't apply in my working tree due to
the other previously-queued changes, but it's just patch-monkey
work.
I thought you might pick up on the damn "less" issue in the help
output... ;-)
To handle that issue, I've decided to do the same thing that
man(1) does. The man command does the same thing as crash, i.e,
it uses "/usr/bin/less -isr" by default, but allows its override
with a "MANPAGER" environment variable. So I'm going to allow users
to hang themselves with CRASHPAGER environment variable. I hadn't
thought of using it as part of the help output, but it should
work there as well.
Thanks,
Dave