How can one mark a flag as required with gflags?

人盡茶涼 提交于 2019-12-07 07:22:39

问题


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


回答1:


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)


来源:https://stackoverflow.com/questions/37305560/how-can-one-mark-a-flag-as-required-with-gflags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!