yanson694 / shflags

Automatically exported from code.google.com/p/shflags
0 stars 0 forks source link

Boolean flags don't work as documented #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the following sample file (call it bug.sh):

#!/bin/bash - 

. ./shflags

DEFINE_boolean foo false \
    "To foo or not to foo"

# Parse command line options.
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

echo ${FLAGS_foo}

2. Run and observe the output of the following commands:

$ ./bug.sh --foo
0
$ ./bug.sh --nofoo
1
$ ./bug.sh --foo=0
flags:WARN getopt: option `--foo' doesn't allow an argument
 --
flags:FATAL unable to parse provided options with getopt.
$ ./bug.sh --foo=1
flags:WARN getopt: option `--foo' doesn't allow an argument
 --
flags:FATAL unable to parse provided options with getopt.

What is the expected output? What do you see instead?
See above

What version of the product are you using? On what operating system?
gflags 1.0.3 on Mac. I'm using the getopt from homebrew, so it does support 
long arguments.

Please provide any additional information below.
The comments in shflags might be out of date. Specifically, the section about 
boolean flags includes this:

#   Alternately, you can say
#     --myflag=true  or --myflag=t or --myflag=0  or
#     --myflag=false or --myflag=f or --myflag=1

Original issue reported on code.google.com by diwakerg...@gmail.com on 6 Mar 2012 at 10:59

GoogleCodeExporter commented 9 years ago
Humm... I'd say the docs are incorrect as they definitely don't reflect the 
implementation. Looking at the Getopt::Long docs for Perl (which turned up 1st 
for me for a 'getopt boolean' search), they say this:

The argument specification is optional. If omitted, the option is considered 
boolean, a value of 1 will be assigned when the option is used on the command 
line.

That reflects the implementation. Just to note, as shell's boolean values are 
swapped, a 0 would be returned instead of a 1.

Original comment by kate.w...@forestent.com on 6 Jan 2013 at 4:54

GoogleCodeExporter commented 9 years ago
Fixed in r171. Updated the docs in the shflags code and removed the incorrect 
alternate usage info.

Original comment by kate.w...@forestent.com on 7 Jan 2013 at 10:11