-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c5f752
commit ca313dc
Showing
7 changed files
with
875 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
GIT_VERSION ?= $(shell git describe --tags --always --dirty) | ||
|
||
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) | ||
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ' | ||
ifdef SOURCE_DATE_EPOCH | ||
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)") | ||
else | ||
BUILD_DATE ?= $(shell date "$(DATE_FMT)") | ||
endif | ||
|
||
PKG=github.com/racing-telemetry/f1-dump/cmd | ||
|
||
LDFLAGS="-X $(PKG).GitCommitSHA=$(GIT_VERSION) -X $(PKG).BuildDate=$(BUILD_DATE) -s -w" | ||
|
||
build: | ||
CGO_ENABLED=0 go build -ldflags $(LDFLAGS) -o f1-dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "f1dump", | ||
Short: "Dump F1 data", | ||
Long: `A helper CLI for dumping F1 data`, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/pkg/errors" | ||
"github.com/racing-telemetry/f1-dump/internal" | ||
"github.com/spf13/cobra" | ||
"runtime" | ||
) | ||
|
||
var ( | ||
GitCommitSHA = "unknown" | ||
BuildDate = "unknown" | ||
) | ||
|
||
type CLIVersionInfo struct { | ||
Version string | ||
GitCommitSHA string | ||
BuildDate string | ||
GoVersion string | ||
Compiler string | ||
Platform string | ||
} | ||
|
||
func NewCmdVersion() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Prints the CLI version", | ||
Long: `Prints the CLI version`, | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
bytes, err := json.Marshal(VersionInfo()) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to marshal version info") | ||
} | ||
|
||
fmt.Println(string(bytes)) | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func VersionInfo() *CLIVersionInfo { | ||
return &CLIVersionInfo{ | ||
Version: internal.Version, | ||
GitCommitSHA: GitCommitSHA, | ||
BuildDate: BuildDate, | ||
GoVersion: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||
} | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(NewCmdVersion()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/racing-telemetry/f1-dump | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/pkg/errors v0.8.1 | ||
github.com/spf13/cobra v1.3.0 | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package internal | ||
|
||
const Version = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/racing-telemetry/f1-dump/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |