Skip to content

Commit

Permalink
add version print
Browse files Browse the repository at this point in the history
  • Loading branch information
tenox7 committed Oct 3, 2024
1 parent 20a15f6 commit fddc985
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
37 changes: 21 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
NAME := stc
GIT_TAG=$(shell git describe --tags --always --dirty)
LDFLAGS=-ldflags "-X main.GitTag=$(GIT_TAG)"

all: $(NAME)
$(NAME): *.go
go build -o $(NAME) .
go build $(LDFLAGS) -o $(NAME) .

cross:
GOOS=linux GOARCH=amd64 go build -a -o $(NAME)-amd64-linux .
GOOS=linux GOARCH=arm go build -a -o $(NAME)-arm-linux .
GOOS=linux GOARCH=arm64 go build -a -o $(NAME)-arm64-linux .
GOOS=darwin GOARCH=amd64 go build -a -o $(NAME)-amd64-macos .
GOOS=darwin GOARCH=arm64 go build -a -o $(NAME)-arm64-macos .
GOOS=freebsd GOARCH=amd64 go build -a -o $(NAME)-amd64-freebsd .
GOOS=openbsd GOARCH=amd64 go build -a -o $(NAME)-amd64-openbsd .
GOOS=netbsd GOARCH=amd64 go build -a -o $(NAME)-amd64-netbsd .
GOOS=solaris GOARCH=amd64 go build -a -o $(NAME)-adm64-solaris .
GOOS=aix GOARCH=ppc64 go build -a -o $(NAME)-ppc64-aix .
GOOS=plan9 GOARCH=amd64 go build -a -o $(NAME)-amd64-plan9 .
GOOS=plan9 GOARCH=arm go build -a -o $(NAME)-arm-plan9 .
GOOS=windows GOARCH=amd64 go build -a -o $(NAME)-amd64-win64.exe
GOOS=windows GOARCH=arm64 go build -a -o $(NAME)-arm64-win64.exe
GOOS=windows GOARCH=386 go build -a -o $(NAME)-arm64-win32.exe
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-linux .
GOOS=linux GOARCH=arm go build $(LDFLAGS) -a -o $(NAME)-arm-linux .
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -a -o $(NAME)-arm64-linux .
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-macos .
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -a -o $(NAME)-arm64-macos .
GOOS=freebsd GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-freebsd .
GOOS=openbsd GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-openbsd .
GOOS=netbsd GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-netbsd .
GOOS=solaris GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-adm64-solaris .
GOOS=aix GOARCH=ppc64 go build $(LDFLAGS) -a -o $(NAME)-ppc64-aix .
GOOS=plan9 GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-plan9 .
GOOS=plan9 GOARCH=arm go build $(LDFLAGS) -a -o $(NAME)-arm-plan9 .
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-win64.exe
GOOS=windows GOARCH=arm64 go build $(LDFLAGS) -a -o $(NAME)-arm64-win64.exe
GOOS=windows GOARCH=386 go build $(LDFLAGS) -a -o $(NAME)-arm64-win32.exe

clean:
rm -f stc stc-*
4 changes: 4 additions & 0 deletions hlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func usage() {
)
}

func printVer() {
fmt.Printf("stc version %v\n", GitTag)
}

func findCfgFile(homeDir string) (string, error) {
getCfgFile := func(dir string) (string, error) {
_, err := os.Stat(dir)
Expand Down
6 changes: 6 additions & 0 deletions stc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var (
target = flag.String("target", "", "Syncthing Target URL")
homeDir = flag.String("homedir", "", "Syncthing Home Directory, used to get API Key and Target")
igCert = flag.Bool("ignore_cert_errors", false, "ignore https/ssl/tls cert errors")
verFlag = flag.Bool("version", false, "print version")
GitTag string
)

type SyncFolder struct {
Expand Down Expand Up @@ -351,6 +353,10 @@ func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
flag.Usage = usage
flag.Parse()
if *verFlag {
printVer()
os.Exit(0)
}

a, t, err := cfg(*apiKey, *target, *homeDir)
if err != nil {
Expand Down

0 comments on commit fddc985

Please sign in to comment.