-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
92 lines (83 loc) · 1.82 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2016 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
// periph-info prints out information about the loaded periph drivers.
package main
import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"periph.io/x/conn/v3/driver/driverreg"
"periph.io/x/host/v3"
)
func printDrivers(drivers []driverreg.DriverFailure) {
if len(drivers) == 0 {
fmt.Print(" <none>\n")
return
}
max := 0
for _, f := range drivers {
if m := len(f.D.String()); m > max {
max = m
}
}
for _, f := range drivers {
fmt.Printf("- %-*s: %v\n", max, f.D, f.Err)
}
}
func mainImpl() error {
verbose := flag.Bool("v", false, "verbose mode")
flag.Parse()
if !*verbose {
log.SetOutput(ioutil.Discard)
}
log.SetFlags(log.Lmicroseconds)
if flag.NArg() != 0 {
return errors.New("unexpected argument, try -help")
}
state, err := host.Init()
if err != nil {
return err
}
fmt.Printf("Drivers loaded and their dependencies, if any:\n")
if len(state.Loaded) == 0 {
fmt.Print(" <none>\n")
} else {
max := 0
for _, d := range state.Loaded {
if m := len(d.String()); m > max {
max = m
}
}
for _, d := range state.Loaded {
p := d.Prerequisites()
a := d.After()
if len(p) == 0 && len(a) == 0 {
fmt.Printf("- %s\n", d)
continue
}
fmt.Printf("- %-*s:", max, d)
if len(p) != 0 {
fmt.Printf(" %s", p)
}
if len(a) != 0 {
fmt.Printf(" optional: %s", a)
}
fmt.Printf("\n")
}
}
fmt.Printf("Drivers skipped and the reason why:\n")
printDrivers(state.Skipped)
fmt.Printf("Drivers failed to load and the error:\n")
printDrivers(state.Failed)
return err
}
func main() {
if err := mainImpl(); err != nil {
fmt.Fprintf(os.Stderr, "periph-info: %s.\n", err)
os.Exit(1)
}
}