Skip to content

Commit

Permalink
feat: built in version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed Jan 10, 2024
1 parent c32bbac commit df6337d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cmd/HeyFileGo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"os"
)

var Version = "unknown"

func init() {
config.Init(Version)
}

func apiServer(listener net.Listener) {
var err error
engine := router.Init()
Expand Down Expand Up @@ -63,6 +69,7 @@ func main() {
slog.Info("获取网卡信息失败", "err", err)
} else {
printer := netInterface.NewPrinter().WithEth(config.Commands.Ssl, fmt.Sprint(listener.Addr().(*net.TCPAddr).Port))

switch len(ethList) {
case 0:
slog.Warn("没有找到可用网卡!")
Expand Down
4 changes: 3 additions & 1 deletion internal/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ var Commands struct {
Path string
}

func initCommands() {
func initCommands(Version string) {
Commands.App = kingpin.New("HeyFileGo", "A lightweight file transfer tool.")
Commands.App.Version(Version)
Commands.App.VersionFlag.Short('v')
Commands.App.HelpFlag.Short('h')
Commands.App.Flag("ssl", "Enable tls for transfer.").Short('s').BoolVar(&Commands.Ssl)
Commands.App.Flag("port", "Specify port.").Short('p').UintVar(&Commands.Port)
Expand Down
4 changes: 2 additions & 2 deletions internal/config/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

func init() {
initCommands()
func Init(Version string) {
initCommands(Version)
initServer()
}
3 changes: 2 additions & 1 deletion scripts/build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@echo off
SET /p v=Version:
cd web
call pnpm run build
cd ..
release ./cmd/HeyFileGo
release ./cmd/HeyFileGo --ldflags="-X main.Version=%v%"

0 comments on commit df6337d

Please sign in to comment.