dtpfia3334 2017-10-12 09:46
浏览 26
已采纳

Golang布尔标志解析限制

Can someone elaborate a little more about an explanation from official golang documentation about cmd syntax for boolean flags.

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.

I don't get the point. Could you explain it or give an example?

  • 写回答

1条回答 默认 最新

  • dongtao5055 2017-10-12 09:52
    关注

    If you run cmd -x * in a shell, the shell will try to expand the * into the list of all files in the current directory. If the current directory contains exactly one file that is named "0" or "false", the shell will execute cmd -x 0 or cmd -x false respectively.

    It is unclear whether cmd -x false is meant to be understood as cmd -x=true false (with "false" being a positional argument), or cmd -x=false. So the flag package forces you to make it explicit by requiring the equal sign.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿