yanson694 / shflags

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

Enhancement: Add the ability to have a flag without the negate option #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Sometimes it's useful to have a boolean flag that doesn't have a negate option.
For example:
DEFINE_boolean 'force' false 'force overwriting' 'f'

It's not needed to have a --noforce for this option as omitting the flag has 
the same result.

We can add an exclamation mark at the end of the flag name to indicate there is 
no negate option for this flag.
In the above eample the new define statement would be:
DEFINE_boolean 'force!' false 'force overwriting' 'f'

The patch already has this for the build in help flag.
DEFINE_boolean 'help!' false 'show this help' 'h'

Original issue reported on code.google.com by pvanderdoes@gmail.com on 9 Jan 2013 at 3:24

Attachments:

GoogleCodeExporter commented 9 years ago
If accepted the calls to the two functions:
_flags_underscoreName()
_flags_removeExclamationName()

could probably be replaced by a new function like
_flags_cleanupName

Which in itself would either call the above two functions or would do what the 
above two functions do.

Original comment by pvanderdoes@gmail.com on 9 Jan 2013 at 3:27

GoogleCodeExporter commented 9 years ago
Argh, wrong patch uploaded

Original comment by pvanderdoes@gmail.com on 9 Jan 2013 at 3:34

GoogleCodeExporter commented 9 years ago
Correct patch

Original comment by pvanderdoes@gmail.com on 9 Jan 2013 at 3:41

Attachments:

GoogleCodeExporter commented 9 years ago
Hmmm, need some more thought into this. Test for nohelp fails, as the option 
nohelp isn't generated with the above patch. There is also another small bug in 
the patch, the exclamation mark isn't stripped during the genOptString function 
(I know how to fix, just seemed redundant to this because of the nohelp fails)

Original comment by pvanderdoes@gmail.com on 10 Jan 2013 at 3:20

GoogleCodeExporter commented 9 years ago
I guess the test for the nohelp is correct to fail, as there is no option 
nohelp anymore. If this would be implemented the test would need to change, or 
the test is redundant and can be removed.

Original comment by pvanderdoes@gmail.com on 10 Jan 2013 at 2:31

GoogleCodeExporter commented 9 years ago
Well this a better patch, I uses built-in functionality if able to.

Original comment by pvanderdoes@gmail.com on 21 Jan 2013 at 7:24

Attachments:

GoogleCodeExporter commented 9 years ago
And we just keep fixing it :)

Original comment by pvanderdoes@gmail.com on 22 Jan 2013 at 7:21

Attachments: