Skip to content

Instantly share code, notes, and snippets.

@tcnksm
Created November 3, 2013 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcnksm/7288123 to your computer and use it in GitHub Desktop.
Save tcnksm/7288123 to your computer and use it in GitHub Desktop.
Parse command line argument by Go
package main
import (
"flag"
"fmt"
"time"
)
var (
message = flag.String("message", "Hello!", "What to say")
delay = flag.Duration("delay", 2*time.Second, "How long to wait")
)
func main() {
flag.Parse()
fmt.Println(*message)
time.Sleep(*delay)
fmt.Println("Done")
}
go run flag.go --help
go run flag.go
go run flag.go -message "Hello world"
go run flag.go -message "Hello world" -delay 5m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment