kingpin中Bool型参数的使用-golang

栏目: Go · 发布时间: 6年前

内容简介:在使用go的kingpin作为启动参数传递的时候,遇到了一个问题,就是当传bool型的参数时总是出错:默认情况下不传代表的是false,即在使用时咋启动参数中不输入这个参数的信息,当输入的时候是表示true。下面上代码看下传参信息:

在使用 go 的kingpin作为启动参数传递的时候,遇到了一个问题,就是当传bool型的参数时总是出错:

默认情况下不传代表的是false,即在使用时咋启动参数中不输入这个参数的信息,当输入的时候是表示true。

下面上代码看下传参信息:

var (
      flag = kingpin.Command("server", "desc")
      flagBool = server.Flag("flagBool", "desc of param").Bool()
)
func main() {
        switch kingpin.Parse() {
          case "server" : 
               if *flagBool {
                  fmt.println("flagBool", *flagBool) 
               }
        }
}

启动参数如下:

#代表使用bool默认值false
 go run  main.go  server 

#代表使用bool默认值true
 go run  main.go  server  --flagBool

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

TED Talks Storytelling: 23 Storytelling Techniques from the Best

TED Talks Storytelling: 23 Storytelling Techniques from the Best

Akash Karia / CreateSpace Independent Publishing Platform / 2015-1-11 / USD 6.99

"Every speaker can put these ideas into practice immediately -- and they should!" ~ Dr. Richard C. Harris, Certified World Class Speaking Coach "An insightful read" ~Dennis Waller, Top 500 Revie......一起来看看 《TED Talks Storytelling: 23 Storytelling Techniques from the Best》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具