github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/exp/ectool/ectool.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "os" 7 "time" 8 ) 9 10 type cmd func(...string) error 11 12 var ( 13 // various commands add themselves to this map as part of 14 // their init. 15 commands map[string]cmd 16 lpcdebug = flag.Bool("lpcdebug", true, "Enable lpc debug prints") 17 chips = make(map[string]func(ioport, ioaddr, time.Duration, time.Duration, debugf) ec) 18 defaultChip = flag.String("chip", "lpc", "Which chip to use") 19 chip = newLPC 20 ) 21 22 func debug(s string, v ...interface{}) { 23 fmt.Printf(s, v...) 24 } 25 26 func main() { 27 d := debug 28 flag.Parse() 29 if !*lpcdebug { 30 d = nil 31 } 32 p, err := newDevPorts(d) 33 if err != nil { 34 fmt.Fprintf(os.Stderr, "%v", err) 35 } 36 fmt.Printf("p %v\n", p) 37 if c, ok := chips[*defaultChip]; !ok { 38 fmt.Fprintf(os.Stderr, "Unknown chip %v: Choices: %v\n", *defaultChip, chips) 39 os.Exit(1) 40 } else { 41 chip = c 42 } 43 44 ec := chip(p, ecLpcAddrHostCmd, time.Second*10, time.Second*10, d) 45 // valid command? 46 // TODO: use the command table for real? But what should the type be? interface{}, err? 47 a := flag.Args() 48 if len(a) == 0 { 49 fmt.Printf("usage: ectool command [args]\n") 50 os.Exit(1) 51 } 52 switch a[0] { 53 case "info": 54 d, err := info(ec) 55 fmt.Printf("%v, %v\n", d, err) 56 default: 57 fmt.Printf("Unknown: %v", a) 58 } 59 }