golang flag使用示例


  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使用示例)