Skip to content

Commit

Permalink
feat: add version param (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
pancsta committed Mar 1, 2024
1 parent 8118506 commit 45c7038
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/am-dbg/debugger/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func StartRCP(rcvr *RPCServer) {
l, err := net.Listen("tcp", url)
if err != nil {
rcvr.Mach.AddErr(err)
// TODO nice err msg
panic(err)
}
log.Println("RPC server started at", url)
Expand Down
17 changes: 17 additions & 0 deletions tools/am-dbg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"runtime/debug"
"time"

"github.com/spf13/cobra"
Expand All @@ -22,6 +23,7 @@ const (
cliParamServerURL string = "server-url"
cliParamAmDbgURL string = "am-dbg-url"
cliParamEnableMouse string = "enable-mouse"
cliParamVersion string = "version"
)

func main() {
Expand Down Expand Up @@ -50,11 +52,17 @@ func getRootCmd() *cobra.Command {
"Debug this instance of am-dbg with another one")
rootCmd.Flags().Bool(cliParamEnableMouse, false,
"Enable mouse support")
rootCmd.Flags().Bool(cliParamVersion, false,
"Print version and exit")
return rootCmd
}

func cliRun(cmd *cobra.Command, _ []string) {
// params
version, err := cmd.Flags().GetBool(cliParamVersion)
if err != nil {
panic(err)
}
logFile := cmd.Flag(cliParamLogFile).Value.String()
logLevelInt, err := cmd.Flags().GetInt(cliParamLogLevel)
if err != nil {
Expand All @@ -68,6 +76,15 @@ func cliRun(cmd *cobra.Command, _ []string) {
panic(err)
}

if version {
build, ok := debug.ReadBuildInfo()
if !ok {
panic("No build info available")
}
fmt.Println(build.Main.Version)
os.Exit(0)
}

// file logging
if logLevel > 0 && logFile != "" {
_ = os.Remove(logFile)
Expand Down

0 comments on commit 45c7038

Please sign in to comment.