Skip to content

Commit

Permalink
Add version printing
Browse files Browse the repository at this point in the history
  • Loading branch information
JonEllis committed Jan 31, 2022
1 parent 45f19d5 commit d203855
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BUILDOPT := -ldflags '-s -w'
VERSION := $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
BUILDOPT := -ldflags "-s -w -X main.version=$(VERSION)"
SOURCES := $(wildcard *.go)
VERSION := $(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match)

build: fmt $(SOURCES) clean
@$(foreach FILE, $(SOURCES), echo $(FILE); go build $(BUILDOPT) -o bin/`basename $(FILE) .go` $(FILE);)
Expand Down
24 changes: 21 additions & 3 deletions satisfactory-viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import (
)

var (
ip string
port uint
savePath string
ip string
port uint
savePath string
printVersion bool

version string

//go:embed templates
templates embed.FS
Expand Down Expand Up @@ -62,6 +65,10 @@ func configureCommand() *cobra.Command {
Use: "satisfactory [flags] save-directory",
Short: "HTTP server to list Satisfactory saves and link to download or view them in satisfactory calculator.",
Args: func(cmd *cobra.Command, args []string) error {
if printVersion {
return nil
}

if len(args) < 1 {
return errors.New("The path to your Satisfactory saves directory is required")
}
Expand Down Expand Up @@ -89,10 +96,21 @@ func configureCommand() *cobra.Command {
"",
"The ip address to listen on for HTTP requests")

cmd.Flags().BoolVarP(&printVersion,
"version",
"v",
false,
"Print the current version")

return cmd
}

func run(cmd *cobra.Command, args []string) error {
if printVersion {
fmt.Println(version)
return nil
}

http.HandleFunc("/", index)

saveServer := http.FileServer(http.Dir(savePath))
Expand Down

0 comments on commit d203855

Please sign in to comment.