6

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.)

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958

1 Answers1

6

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)
jrock
  • 245
  • 3
  • 10