Golang中的标志(flags)是否绝对需要值?

huangapple go评论75阅读模式
英文:

Do flags in Golang absolutely need values?

问题

使用golang中的flag包,我可以拥有只需要知道其是否存在的标志吗?就像rails中的"-s"标志一样,该标志没有任何值,但程序可以知道标志"s"是否存在。

英文:

With the flag package in golang, can I have flags that I only need to know the presence of them? Like rails -s, the flag "s" does not have any value, but program can know the presence of the flag s.

答案1

得分: 5

是的,在flag包文档中,它说可能的命令行标志语法之一是-flag。你可以尝试使用BoolBoolVar函数创建一个布尔标志,并查看它是否按预期工作。

英文:

Yes, in the flag package documentation, it says that one of the possible command line flag syntaxes is -flag. You should try making a boolean flag with the Bool or BoolVar functions and see if it works the expected way.

huangapple
  • 本文由 发表于 2014年7月21日 04:04:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/24854410.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定