Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one mark a flag as required with gflags?

Tags:

python

gflags

I use gflags like this:

flags.DEFINE_string('logdir', None,
                    'Directory where logs are stored.')

However, I would like gflags to show the help when somebody does not define --logdir. How can I make this flag required?

(This looks a bit as if it should be possible, but I couldn't find any documentation about how to use gflags with Python.)

like image 996
Martin Thoma Avatar asked May 18 '16 16:05

Martin Thoma


1 Answers

Your code should look something like this. The MarkFlagAsRequired must come before FLAGS(argv) call.

def main(argv):
    gflags.MarkFlagAsRequired('logdir')      
    argv = gflags.FLAGS(argv)
like image 62
jrock Avatar answered Oct 09 '22 23:10

jrock