Skip to content

Commit

Permalink
Support version command
Browse files Browse the repository at this point in the history
  • Loading branch information
hzyitc committed Oct 22, 2022
1 parent c8809dd commit d7570f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions buildAllPlatforms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ OUTPUT="bin/"
PROGRAM="mnh"
LDFLAGS="-s -w"

ver="$(git describe --tags --match "v*" --dirty="" 2>/dev/null || git log -1 --pretty=format:"v0.0.0-%h" 2>/dev/null || echo "v0.0.0")"
[ -n "$(git status --porcelain |& grep -Ev '^\?\?')" ] && ver="$ver-$(date +"%Y%M%d-%H%m%S")"
LDFLAGS="$LDFLAGS -X main.version=$ver"

mkdir -p "$OUTPUT"
rm -f "$OUTPUT/${PROGRAM}-"*

Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ import (
"github.com/hzyitc/mnh/routerForward"
)

var version = "v0.0.0"

var rootCmd = &cobra.Command{
Use: "mnh",
Short: "A NAT hole punching tool that allows peers directly connect to your NATed server without client.",
Long: "mnh is a tool that makes exposing a port behind NAT possible.\n" +
"mnh client will produce an ip:port pair for your NATed server which can be used for public access.",
}

var versionCmd = &cobra.Command{
Use: "version",
Run: func(cmd *cobra.Command, args []string) {
print(version)
},
}

var tcpCmd = &cobra.Command{
Use: "tcp",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -118,6 +127,7 @@ func runHook(event string, errmsg string, port string, addr string) {
}

func main() {
rootCmd.AddCommand(versionCmd)
tcpCmdRegister(rootCmd)
udpCmdRegister(rootCmd)

Expand Down

0 comments on commit d7570f5

Please sign in to comment.