go

                   simple, fast, safe, concurrent, fun
  1. Code
  2. Search
  3. Subscribe
  4. Archive
  5. Random

explorations into google's new language by nick quaranto

Newer
Older
  • 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);
    }
    # Makefile
    include $(GOROOT)/src/Make.$(GOARCH)
     
    TARG=flag
    GOFILES=\
            flag.go
     
    include $(GOROOT)/src/Make.cmd
    
    Compile and run away:
    % 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 ()

    1. tmblrmailfor liked this
    2. bubaleh liked this
    3. gliermo liked this
    4. lituliliro liked this
    5. 2puntocero reblogged this from golang
    6. kidpollo liked this
    7. golang posted this

Field Notes Theme. Designed by Manasto Jones. Powered by Tumblr.