有人可以详细说明官方 golang 文档中关于 bool 标志的 cmd 语法的解释吗。
One or two minus signs may be used; they are equivalent. The last form is not permitted for boolean flags because the meaning of the command
cmd -x *
will change if there is a file called 0, false, etc. You must use the -flag=false form to turn off a boolean flag.
我不明白。你能解释一下或举个例子吗?
最佳答案
如果您在 shell 中运行 cmd -x *
,shell 将尝试将 *
扩展到当前目录中所有文件的列表中。如果当前目录恰好包含一个名为“0”或“false”的文件,则 shell 将分别执行 cmd -x 0
或 cmd -x false
。
不清楚 cmd -x false
是要被理解为 cmd -x=true false
(“false”是一个位置参数),还是 cmd -x=false
。因此标志包会强制您通过要求等号来使其显式化。
关于Golang boolean flag 解析限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46706417/