码迷,mamicode.com
首页 > 其他好文 > 详细

golang flag使用示例

时间:2015-08-31 19:56:47      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:


  1. package main

  2. import (

  3. "fmt"

  4. "flag"

  5. )


  6. func main(){


  7. data_path := flag.String("D","/home/manu/sample/","DB data path")

  8. log_file := flag.String("l","/home/manu/sample.log","log file")

  9. nowait_flag :=flag.Bool("W",false,"do not wait until operation completes")


  10. flag.Parse()


  11. var cmd string = flag.Arg(0);


  12. fmt.Printf("action : %s\n",cmd)

  13. fmt.Printf("data path: %s\n",*data_path)

  14. fmt.Printf("log file : %s\n",*log_file)

  15. fmt.Printf("nowait : %v\n",*nowait_flag)


  16. fmt.Printf("-------------------------------------------------------\n")


  17. fmt.Printf("there are %d non-flag input param\n",flag.NArg())

  18. for i,param := range flag.Args(){

  19. fmt.Printf("#%d :%s\n",i,param)

  20. }



  21. }

golang flag使用示例

标签:

原文地址:http://my.oschina.net/ifraincoat/blog/499697

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!