github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/apps/pkg-config/getopt_test.go (about) 1 // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "os" 9 ) 10 11 func _main() { 12 var c int 13 14 OptErr = 0 15 for { 16 if c = Getopt("a:bh"); c == EOF { 17 break 18 } 19 switch c { 20 case 'a': 21 println("a=", OptArg) 22 case 'b': 23 println("i:on") 24 case 'h': 25 println("usage: example [-a foo|-b|-h]") 26 os.Exit(1) 27 } 28 } 29 30 for n := OptInd; n < len(os.Args); n++ { 31 println(os.Args[n]) 32 } 33 }