Skip to content

Commit

Permalink
2.0: rewrite, flatten code base
Browse files Browse the repository at this point in the history
Now that I have another year of development with Go under my belt
I thought I would re-write this a bit to clean up the unnecessary
directories and packages.
  • Loading branch information
powersj committed Nov 18, 2021
1 parent 3e4965f commit 373880c
Show file tree
Hide file tree
Showing 22 changed files with 889 additions and 443 deletions.
67 changes: 0 additions & 67 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/coverage.out
/go.sum
/pciids
dist
site
28 changes: 14 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
linters:
enable:
- dupl
- errorlint
- funlen
- gocritic
- godot
- gofumpt
- goimports
- gomnd
- gosec
- lll
- misspell
- whitespace
- wrapcheck
enable-all: true
disable:
- forbidigo
- golint
- interfacer
- maligned
- wsl
- scopelint
- gochecknoinits
- exhaustivestruct
- testpackage
- paralleltest
- gochecknoglobals
- varnamelen
linters-settings:
lll:
line-length: 100
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ branches:
- master
language: go
go:
- 1.14.x
- 1.15.x
- 1.17.x
dist: bionic
install:
- go get -t -v ./...
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${TRAVIS_HOME}/bin v1.33.0
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${TRAVIS_HOME}/bin v1.43.0
- pyenv global 3.8
- pip install --user mkdocs-material
script:
Expand Down
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
.PHONY: all
all: build

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

.PHONY: clean
clean:
rm -f pciids coverage.out go.sum
rm -f pciids coverage.out
rm -rf dist/ site/

.PHONY: docs
docs:
mkdocs build

.PHONY: docs-api
docs-api:
echo "View docs at: http://localhost:6060/pkg/pciids/"
godoc -http=localhost:6060

.PHONY: lint
lint:
golangci-lint run

.PHONY: release
release: clean
goreleaser

.PHONY: release-snapshot
release-snapshot: clean
goreleaser --rm-dist --skip-publish --snapshot

.PHONY: test
test:
go test -cover -coverprofile=coverage.out ./pkg/...
go test -cover -coverprofile=coverage.out ./...

.PHONY: test-coverage
test-coverage: test
go tool cover -html=coverage.out

.PHONY: all build clean docs docs-api lint release release-snapshot test test-coverage
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Here are some examples:

```text
$ pciids 1d0f efa1
1d0f:efa1 - Amazon.com, Inc. Elastic Fabric Adapter (EFA)
1d0f:efa1 - Amazon.com, Inc. Elastic Fabric Adapter (EFA)
$ pciids 10de 2206 10de 1467
10de:2206 10de:1467 - NVIDIA Corporation GA102 [GeForce RTX 3080]
```
Expand Down Expand Up @@ -49,12 +49,12 @@ The `--debug` flag to produce additional output while running:

```json
$ pciids --json 121a 0009 121a 0009
DEBU Looking up 121a:0009 121a:0009
DEBU Downloading https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids
DEBU looking up 121a:0009 121a:0009
DEBU downloading https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids
DEBU 200 OK
DEBU Parsing vendor IDs
DEBU Parsing PCI IDs
DEBU Found 1 results
DEBU parsing vendor IDs
DEBU parsing PCI IDs
DEBU found 1 results
121a:0009 121a:0009 - 3Dfx Interactive, Inc. Voodoo5 AGP 5500/6000
```

Expand Down
9 changes: 0 additions & 9 deletions app/pciids/main.go

This file was deleted.

30 changes: 10 additions & 20 deletions app/pciids/cmd/root.go → cli.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package cmd
package main

import (
"encoding/json"
"fmt"
"os"

"github.com/powersj/pciids/pkg/ids"
"github.com/powersj/pciids/pkg/query"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

const (
version = "v1.4.0"
numDeviceIDs = 2
numSubDeviceIDs = 4
)

var (
debugOutput bool
jsonOutput bool
Expand Down Expand Up @@ -47,7 +38,8 @@ $ pciids 10de 2206 10de 1467
// Called before all commands to setup general run-time settings.
func setup(cmd *cobra.Command, args []string) {
log.SetFormatter(&log.TextFormatter{
DisableTimestamp: true,
DisableTimestamp: true,
DisableLevelTruncation: true,
})

if debugOutput {
Expand All @@ -70,19 +62,17 @@ func args(cmd *cobra.Command, args []string) error {

// Base command operations.
func root(cmd *cobra.Command, args []string) error {
var ids []ids.PCIID
var ids []PCIID
var err error

if len(args) == numSubDeviceIDs {
ids, err = query.SubDevice(args[0], args[1], args[2], args[3])
if err != nil {
return errors.Wrap(err, "Error while querying for device")
}
ids, err = QuerySubDevice(args[0], args[1], args[2], args[3])
} else {
ids, err = query.Device(args[0], args[1])
if err != nil {
return errors.Wrap(err, "Error while querying for device")
}
ids, err = QueryDevice(args[0], args[1])
}

if err != nil {
return errors.Wrap(err, "Error while querying for device")
}

if jsonOutput {
Expand Down
19 changes: 14 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
module github.com/powersj/pciids

go 1.14
go 1.17

require (
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.3.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading

0 comments on commit 373880c

Please # to comment.