github.com/go-darwin/sys@v0.0.0-20220510002607-68fd01f054ca/testdata/testprog/main.go (about) 1 // Copyright 2015 The Go Authors. 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 "os" 8 9 var cmds = map[string]func(){} 10 11 func register(name string, f func()) { 12 if cmds[name] != nil { 13 panic("duplicate registration: " + name) 14 } 15 cmds[name] = f 16 } 17 18 func registerInit(name string, f func()) { 19 if len(os.Args) >= 2 && os.Args[1] == name { 20 f() 21 } 22 } 23 24 func main() { 25 if len(os.Args) < 2 { 26 println("usage: " + os.Args[0] + " name-of-test") 27 return 28 } 29 f := cmds[os.Args[1]] 30 if f == nil { 31 println("unknown function: " + os.Args[1]) 32 return 33 } 34 f() 35 }