Skip to content

Commit 6532af4

Browse files
authored
Merge pull request #72 from numtide/fix/id-lookup
fix: lookup of pci and usb ids when specifying hardware features
2 parents 77c54df + 17553f3 commit 6532af4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

cmd/root.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"os"
7+
"slices"
78
"strings"
89

910
"github.com/numtide/nixos-facter/pkg/hwinfo"
@@ -91,15 +92,25 @@ func init() {
9192
"sysfs", "udev", "block", "wlan",
9293
}
9394

95+
// we strip default and int from the feature list
96+
allFeatures := hwinfo.ProbeFeatureStrings()
97+
slices.DeleteFunc(allFeatures, func(str string) bool {
98+
switch str {
99+
case "default", "int":
100+
return true
101+
default:
102+
return false
103+
}
104+
})
105+
94106
f.StringSliceVarP(
95107
&hardwareFeatures,
96108
"hardware-features",
97109
"f",
98110
defaultFeatures,
99111
fmt.Sprintf(
100112
"Hardware features to probe. Possible values are %s",
101-
// we strip default from the feature list
102-
strings.Replace(strings.Join(hwinfo.ProbeFeatureStrings(), ","), "default,", "", 1),
113+
strings.Join(allFeatures, ","),
103114
),
104115
)
105116
}

pkg/hwinfo/hwinfo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func Scan(probes []ProbeFeature) ([]Smbios, []*HardwareItem, error) {
3131
// initialise the struct to hold scan data
3232
data := (*C.hd_data_t)(unsafe.Pointer(C.calloc(1, C.size_t(unsafe.Sizeof(C.hd_data_t{})))))
3333

34+
// ProbeFeatureInt needs to always be set, otherwise we don't get pci and usb vendor id lookups.
35+
// https://github.com/openSUSE/hwinfo/blob/c87f449f1d4882c71b0a1e6dc80638224a5baeed/src/hd/hd.c#L597-L605
36+
C.hd_set_probe_feature(data, C.enum_probe_feature(ProbeFeatureInt))
37+
3438
// set the hardware probes to run
3539
for _, probe := range probes {
3640
C.hd_set_probe_feature(data, C.enum_probe_feature(probe))

0 commit comments

Comments
 (0)