Skip to content

Commit

Permalink
improved Makefile
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
markusressel committed Apr 4, 2022
1 parent cab80d2 commit 581b346
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bin
fan2go.db
dist
fan2go*.db
fan2go*.yaml
test.db
28 changes: 18 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
BINARY_NAME=fan2go
OUTPUT_DIR=bin/
GO_FLAGS ?=
NAME := fan2go
OUTPUT_BIN ?= bin/${NAME}
PACKAGE := github.com/markusressel/$(NAME)
GIT_REV ?= $(shell git rev-parse --short HEAD)
SOURCE_DATE_EPOCH ?= $(shell date +%s)
DATE ?= $(shell date -u -d @${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
VERSION ?= 0.6.0

build:
go build -o ${OUTPUT_DIR}${BINARY_NAME} main.go
test: ## Run all tests
@go clean --testcache && go test -v ./...

run:
go build -o ${OUTPUT_DIR}${BINARY_NAME} main.go
./${OUTPUT_DIR}${BINARY_NAME}
build: ## Builds the CLI
@go build ${GO_FLAGS} \
-ldflags "-w -s -X ${PACKAGE}/cmd.version=${VERSION} -X ${PACKAGE}/cmd.commit=${GIT_REV} -X ${PACKAGE}/cmd.date=${DATE}" \
-a -tags netgo -o ${OUTPUT_BIN} main.go

test:
sudo go test -v ./...
run:
go build -o ${OUTPUT_BIN} main.go
./${OUTPUT_BIN}

clean:
go clean
rm ${OUTPUT_DIR}${BINARY_NAME}
rm ${OUTPUT_BIN}
3 changes: 0 additions & 3 deletions cmd/fan/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ var rpmCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
pterm.DisableOutput()

fanIdFlag := cmd.Flag("id")
fanId := fanIdFlag.Value.String()

fan, err := getFan(fanId)
if err != nil {
return err
Expand Down
3 changes: 0 additions & 3 deletions cmd/fan/speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ var speedCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
pterm.DisableOutput()

fanIdFlag := cmd.Flag("id")
fanId := fanIdFlag.Value.String()

fan, err := getFan(fanId)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
)

var (
version, commit, date = "dev", "dev", ""

cfgFile string
noColor bool
noStyle bool
Expand Down
3 changes: 0 additions & 3 deletions cmd/sensor/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ var Command = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
pterm.DisableOutput()

sensorIdFlag := cmd.Flag("id")
sensorId := sensorIdFlag.Value.String()

sensor, err := getSensor(sensorId)
if err != nil {
return err
Expand Down
12 changes: 11 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ import (
"github.com/spf13/cobra"
)

var long bool

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of fan2go",
Long: `All software has versions. This is fan2go's`,
Run: func(cmd *cobra.Command, args []string) {
ui.Printfln("0.6.0")
if verbose {
ui.Printfln("%s-%s-%s", version, commit, date)
} else if long {
ui.Printfln("%s-%s", version, commit)
} else {
ui.Printfln("%s", version)
}
},
}

func init() {
versionCmd.Flags().BoolVarP(&long, "long", "l", false, "Show the long version")

rootCmd.AddCommand(versionCmd)
}

0 comments on commit 581b346

Please sign in to comment.