From 60160db23a589406ca26d65d1cec2824feb1e2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Mon, 18 Aug 2025 22:00:03 +0200 Subject: [PATCH] fix(cmd): restore --version flag for compatibility (#10269) ### Purpose This was lost / replaced when introducing the "version" command. However, the documentation still lists the flag - actually under the serve command, but that can be omitted. Common convention for CLI programs is to accept it as a flag. ### Testing ``` $ bin/syncthing --help Usage: syncthing [flags] Flags: -h, --help Show context-sensitive help. -C, --config=PATH Set configuration directory (config and keys) ($STCONFDIR) -D, --data=PATH Set data directory (database and logs) ($STDATADIR) -H, --home=PATH Set configuration and data directory ($STHOMEDIR) --version Show current version, then exit Commands: serve Run Syncthing (default) cli Command line interface for Syncthing browser Open GUI in browser, then exit decrypt Decrypt or verify an encrypted folder device-id Show device ID, then exit generate Generate key and config, then exit paths Show configuration paths, then exit upgrade Perform or check for upgrade, then exit version Show current version, then exit debug Various debugging commands install-completions Print commands to install shell completions Run "syncthing --help" for more information on a command. ``` ``` $ bin/syncthing --version syncthing v2.0.3-dev.2.g0f47e944-restore-version-flag "Hafnium Hornet" (go1.24.0 linux-amd64) acolomb@riddo 2025-08-18 19:25:31 UTC ``` ### Documentation Already / *still* listed in the docs under Command Line Operation. --- cmd/syncthing/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 20ad09b9f..d7ff88a07 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -122,9 +122,10 @@ type CLI struct { // subcommands. Their settings take effect on the `locations` package by // way of the command line parser, so anything using `locations.Get` etc // will be doing the right thing. - ConfDir string `name:"config" short:"C" placeholder:"PATH" env:"STCONFDIR" help:"Set configuration directory (config and keys)"` - DataDir string `name:"data" short:"D" placeholder:"PATH" env:"STDATADIR" help:"Set data directory (database and logs)"` - HomeDir string `name:"home" short:"H" placeholder:"PATH" env:"STHOMEDIR" help:"Set configuration and data directory"` + ConfDir string `name:"config" short:"C" placeholder:"PATH" env:"STCONFDIR" help:"Set configuration directory (config and keys)"` + DataDir string `name:"data" short:"D" placeholder:"PATH" env:"STDATADIR" help:"Set data directory (database and logs)"` + HomeDir string `name:"home" short:"H" placeholder:"PATH" env:"STHOMEDIR" help:"Set configuration and data directory"` + VersionFlag bool `name:"version" help:"Show current version, then exit"` Serve serveCmd `cmd:"" help:"Run Syncthing (default)" default:"withargs"` CLI cli.CLI `cmd:"" help:"Command line interface for Syncthing"` @@ -224,6 +225,12 @@ func main() { kongplete.Complete(parser) ctx, err := parser.Parse(os.Args[1:]) parser.FatalIfErrorf(err) + + if entrypoint.VersionFlag { + _ = versionCmd{}.Run() + return + } + err = ctx.Run() parser.FatalIfErrorf(err) }