Golang boolean flag 解析限制

标签 go

有人可以详细说明官方 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 0cmd -x false

不清楚 cmd -x false 是要被理解为 cmd -x=true false(“false”是一个位置参数),还是 cmd -x=false。因此标志包会强制您通过要求等号来使其显式化。

关于Golang boolean flag 解析限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46706417/

相关文章:

email - 去smtp发邮件

mysql - 在 mysql 中使用 gorm 插入类型 []byte 引发 "Error 1241: Operand should contain 1 columns(s)"

go - 在模板之间传递数据

Go 和 chromedp 的 Dockerfile

timer - 如何从 Web 服务器重启(或代码刷新/升级)中恢复 Go 计时器?

postgresql - Golang 使用 migrate with dockertest

json - 通过 application/json curl 请求发送 bool 值

go - 为什么在go例程中给变量赋值后变量会变空?

json - 如何更改 golang 标签的默认操作?

go - 在 golang range 复制所有项目后指向 src slice 的最后一项