How can one mark a flag as required with gflags?
Asked Answered
A

1

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

Alaniz answered 18/5, 2016 at 16:41 Comment(0)
A
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)
Aronson answered 21/7, 2016 at 20:22 Comment(1)
UPDATE: MarkFlagAsRequired is now mark_flag_as_requiredCb

© 2022 - 2024 — McMap. All rights reserved.