Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anilmisirlioglu committed Jan 24, 2022
1 parent 1c5f752 commit ca313dc
Show file tree
Hide file tree
Showing 7 changed files with 875 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Makefile
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
18 changes: 18 additions & 0 deletions cmd/root.go
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)
}
}
59 changes: 59 additions & 0 deletions cmd/version.go
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())
}
13 changes: 13 additions & 0 deletions go.mod
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
)
759 changes: 759 additions & 0 deletions go.sum

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions internal/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package internal

const Version = "0.0.1"
7 changes: 7 additions & 0 deletions main.go
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()
}

0 comments on commit ca313dc

Please sign in to comment.