From 8514d20799cae7a7f9e7b2bc33bf98f208cec8d9 Mon Sep 17 00:00:00 2001 From: Maksim Merzhanov Date: Wed, 18 Feb 2026 11:37:29 +0300 Subject: [PATCH 1/3] cli: remove `could not load config` error log when the default address works --- cli/cli.go | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index ab1a3af8..8ab27ac2 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -437,34 +437,36 @@ func (a *Application) init() { } } -func (a *Application) initApiConnection(c *cli.Context) (err error) { +func (a *Application) initApiConnection(c *cli.Context) error { apiAddr := c.String("api_addr") - var addr string - defer func() { - if err != nil { - return - } - a.api = apiclient.New(addr) - _, err2 := a.api.PeerInfo() - if err2 != nil { - err = fmt.Errorf("could not access api on address %s: %v", addr, err2) - } - }() if apiAddr != "" { - addr = apiAddr - return nil + return a.initApiFromAddr(apiAddr) } - conf, err := config.LoadConfig(eventbus.NewBus()) - if err != nil { - a.logger.Errorf("could not load config, use default api_addr (%s), error: %v", defaultApiAddr, err) - addr = defaultApiAddr + + conf, errConfig := config.LoadConfig(eventbus.NewBus()) + if errConfig == nil { + return a.initApiFromAddr(conf.HttpListenAddress) + } + + errDefault := a.initApiFromAddr(defaultApiAddr) + if errDefault == nil { return nil } - addr = conf.HttpListenAddress - if addr == "" { - return errors.New("httpListenAddress from config is empty") + + a.logger.Errorf("could not load config file, error: %v", errConfig) + a.logger.Errorf("could not connect to default api_addr (%s), error: %v", defaultApiAddr, errDefault) + + return errors.New("no connection to api server") +} + +func (a *Application) initApiFromAddr(addr string) error { + api := apiclient.New(addr) + _, err := api.PeerInfo() + if err != nil { + return fmt.Errorf("could not access api on address %s: %v", addr, err) } + a.api = api return nil } From f34e8832dc19b08b258921e42cf26812254dd5f9 Mon Sep 17 00:00:00 2001 From: Maksim Merzhanov Date: Wed, 18 Feb 2026 11:42:49 +0300 Subject: [PATCH 2/3] cli: fix bootstrap peers display for `me status` --- cli/me.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/me.go b/cli/me.go index 4f209084..f67beee7 100644 --- a/cli/me.go +++ b/cli/me.go @@ -22,7 +22,7 @@ func printStatus(api *apiclient.Client) error { table.AppendBulk([][]string{ {"Download rate", fmt.Sprintf("%s (%s)", stats.NetworkStatsInIECUnits.RateIn, stats.NetworkStatsInIECUnits.TotalIn)}, {"Upload rate", fmt.Sprintf("%s (%s)", stats.NetworkStatsInIECUnits.RateOut, stats.NetworkStatsInIECUnits.TotalOut)}, - {"Bootstrap peers", fmt.Sprintf("%d/%d", stats.TotalBootstrapPeers, stats.ConnectedBootstrapPeers)}, + {"Bootstrap peers", fmt.Sprintf("%d/%d", stats.ConnectedBootstrapPeers, stats.TotalBootstrapPeers)}, {"DNS", formatWorkingStatus(stats.IsAwlDNSSetAsSystem)}, {"SOCKS5 Proxy", formatWorkingStatus(stats.SOCKS5.ListenerEnabled)}, {"SOCKS5 Proxy address", stats.SOCKS5.ListenAddress}, From 1e11aa059d07f8ed4225d92a1ab2614d55378b1e Mon Sep 17 00:00:00 2001 From: Maksim Merzhanov Date: Wed, 18 Feb 2026 12:24:01 +0300 Subject: [PATCH 3/3] cli: add help and version global flags --- cli/cli.go | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 8ab27ac2..9dcc1ea0 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path" + "runtime" "strconv" "strings" @@ -48,21 +49,48 @@ func New(updateType update.ApplicationType) *Application { func (a *Application) Run() { if len(os.Args) == 1 { return - } else if os.Args[1] == WithEnvCommandName { + } + + switch arg := os.Args[1]; arg { + case WithEnvCommandName: // is handled in linux_root_hacks.go return - } else if os.Args[1] == CliCommandName { - // ok, handle here below - } else { - a.logger.Fatalf("Unknown command '%s', try '%s cli -h' for info on cli commands or '%s' to start awl server", os.Args[1], binaryName, binaryName) + case CliCommandName: + err := a.cliapp.Run(os.Args[1:]) + if err != nil { + a.logger.Fatalf("Error occurred: %v", err) + } + os.Exit(0) + case "-h", "--help": + a.printGlobalHelp() + os.Exit(0) + case "-v", "--version": + a.printVersion() + os.Exit(0) + default: + fmt.Printf("Unknown command '%s'. Use '%s -h' for help, or run '%s' to start the server\n", arg, binaryName, binaryName) + os.Exit(-1) } +} - err := a.cliapp.Run(os.Args[1:]) - if err != nil { - a.logger.Fatalf("Error occurred: %v", err) - } +func (a *Application) printGlobalHelp() { + fmt.Printf(`Usage: %s + +Run without a command to start the server. + +Flags: + -h, --help Show context-sensitive help. + -v, --version Show version. + +Commands: + cli Command line interface for Anywherelan + +Run "%s --help" for more information on a command. +`, binaryName, binaryName) +} - os.Exit(0) +func (a *Application) printVersion() { + fmt.Printf("Anywherelan version %s (%s %s-%s)\n", config.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH) } func (a *Application) init() {