golang flag使用示例


  1. package main
    spa

  2. import (
    input

  3. "fmt"
    cmd

  4. "flag"
    string

  5. )
    it


  6. func main(){
    io


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

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

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


  10. flag.Parse()
    co


  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. }

相關文章
相關標籤/搜索