-
flag
Checking out the flag package, Go’s built in command line argument parser. Here’s a simple example:
// flag.go package main import ( "flag" "fmt" ) var code *int = flag.Int("areacode", 716, "give me your codes") func main() { fmt.Printf("Testing out flags!\n"); flag.Parse(); fmt.Println("areacode has value ", *code); }
Compile and run away:# Makefile include $(GOROOT)/src/Make.$(GOARCH) TARG=flag GOFILES=\ flag.go include $(GOROOT)/src/Make.cmd% make /Users/qrush/Progs/8g -o _go_.8 flag.go /Users/qrush/Progs/8l -o flag _go_.8 % ./flag Testing out flags! areacode has value 716 % ./flag -areacode=585 Testing out flags! areacode has value 585
Mindblowing, I know. Also cool:flag.PrintDefaults()gives a nice printout of the command line arguments with default values.Posted on March 10, 2010 with 25 notes ()
-
tmblrmailfor liked this
-
bubaleh liked this
-
gliermo liked this
-
lituliliro liked this
-
2puntocero reblogged this from golang
-
kidpollo liked this
-
golang posted this
-