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 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题