On 07/02/13 17:02, Oliver Kindernay wrote:
> Hi,
>
> I am using AutoOpts for shell scripts (shell-process main). When the
> program is passed -? or --help it output usage to stdout and exits with
> return value 0, the same thing it does when emitting shell code after
> successful command line parsing. When following documentation, using the
> eval builtin like this
>
>      eval "`script-opts \"$@\"`"
>      test -z "${OPTION_CT}" && exit 1
>      test ${OPTION_CT} -gt 0 && shift ${OPTION_CT}
>
> since it's not easy to clearly distinguish between help invocation and
> successful command line parsing the eval just errors on usage output if
> we pass -? to this script.
>
> There can be multiple ways to solve this, for example we can distinguish
> usage invocation by a different exit value.
>
> I have made a two patches, one that passes failure exit code to
> optionUsage(), making it output to stderr. I am not sure the program
> should exit with failure exit code though, so I made the second patch,
> which uses success exit code, but outputs to stderr. I am using
> option_usage_fp global and I am not sure this is documented behaviour
> and correct way to do this.
>
> Both of these patches make the eval work without error when the parser
> is passed -? or --help.
>
> What do you think?

Hi,

I think you hit upon something not fully considered and never bothered me.
"eval"-ing usage text will make the shell unhappy.  It needs fixing.
You are correct that the actual exit code is not important for this
situation, but it is necessary for "normal" applications where the
program logic is in the same process as the option processing.
So, basically, we need to do normal usage processing, but send output
to stderr because stdout is being captured and eval-ed.

I think, additionally, we ought to emit "exit 0" to stdout as well,
eliminating the need for the test && exit.  I think the best solution
is to fiddle "doUsageOpt()" such that when it is called in this context,
it will print "exit 0\n" to stdout, redirect stdout to stderr and then
process the usage normally.

Thank you for pointing this out.

Regards, Bruce

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Autogen-users mailing list
Autogen-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/autogen-users

Reply via email to