Created
November 3, 2013 09:44
-
-
Save tcnksm/7288123 to your computer and use it in GitHub Desktop.
Parse command line argument by Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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