[dev] Re: [dev] Re: [dev] Re: [dev] Re: [dev] [dev] Usage, -h, --help, help, synopsis, …

2010-08-21 Thread yy
2010/8/21 Suraj Kurapati :
> I like to put documentation at the head of a file because that's only
> part anyone will read before deciding if it's worth spending their
> time to delve into the rest of the shell script.  Also, I don't like
> messing up my program's indentation because I have to emit a big block
> of text in it:

#!/bin/sh

USAGE="\
Usage: $0 -flags args
Explain the options here.
You even can even use use shell variables!
"

if [ $# -lt 1]; then
echo -n "$USAGE" 1>&2
exit 1
fi

Is this really so ugly?

-- 
- yiyus || JGL . 4l77.com



[dev] Re: [dev] Re: [dev] Re: [dev] Re: [dev] [dev] Usage, -h, --help, help, synopsis, …

2010-08-18 Thread Connor Lane Smith
2010/8/18 Alexander Teinum :
> I’d like to write a KISS option parser that accepts “program -c -a -f
> some_file”, but not “program -ca -fsome_file”. I prefer to keep the
> rules simple.

Such a simple option set probably doesn't actually *need* a parser. I
don't think any lines would be freed up in dmenu. You'd just add code.
It's got a for loop and a list of strcmps, plus usage(), which could
be done with a goto but I wasn't sure if that's "suckless". It's
really the simplest implementation out there.

> Is it okay to use three dots in the usage text? (See echo’s man page.)
> I think it means that you can repeat what’s before the three dots.

I think "files..." means 1 or more file, and "[files]..." means 0 or more.

> How do you feel about sorting the options? Should it always be done?

I think it should be in the order the programmer gives them. Some
options may be more important, for example.

cls