From 41bfb7a3302ea7e751fb40a6b8b5a021a0634f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Thu, 4 Nov 2021 08:42:55 +0100 Subject: [PATCH] Normalize CLI options to always use two dashes. (#8037) Consistently use double dashes and fix typos -conf, -data-dir and -verify. Applies also to tests running the syncthing binary for consistency. * Fix mismatched option name --conf in cli subcommand. According to the source code comments, the cli option flags should mirror those from the serve subcommand where applicable. That one is actually called --config though. * cli: Fix help text option placeholders. The urfave/cli package uses the Value field of StringFlag to provide a default value, not to name the placeholder. That is instead done with backticks around some part of the Usage field. * cli: Add missing --data flag in subcommand help text. The urfave/cli based option parsing uses a fake flags collection to generate help texts matching the used global options. But the --data option was omitted from it, although it is definitely required when using --config as well. Note that it cannot just be ignored, as some debug stuff actually uses the DB: syncthing cli --data=/bar --config=/foo debug index dump --- cmd/syncthing/cli/main.go | 18 +++++++++--------- cmd/syncthing/cmdutil/util.go | 4 ++-- cmd/syncthing/decrypt/decrypt.go | 2 +- cmd/syncthing/main.go | 4 ++-- lib/locations/locations.go | 6 +++--- lib/syncthing/utils.go | 2 +- test/cli_test.go | 8 ++++---- test/override_test.go | 4 ++-- test/util.go | 2 +- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cmd/syncthing/cli/main.go b/cmd/syncthing/cli/main.go index f1ef9e4a4..8e08b92ef 100644 --- a/cmd/syncthing/cli/main.go +++ b/cmd/syncthing/cli/main.go @@ -61,23 +61,23 @@ func Run() error { fakeFlags := []cli.Flag{ cli.StringFlag{ Name: "gui-address", - Value: "URL", - Usage: "Override GUI address (e.g. \"http://192.0.2.42:8443\")", + Usage: "Override GUI address to `URL` (e.g. \"http://192.0.2.42:8443\")", }, cli.StringFlag{ Name: "gui-apikey", - Value: "API-KEY", - Usage: "Override GUI API key", + Usage: "Override GUI API key to `API-KEY`", }, cli.StringFlag{ Name: "home", - Value: "PATH", - Usage: "Set configuration and data directory", + Usage: "Set configuration and data directory to `PATH`", }, cli.StringFlag{ - Name: "conf", - Value: "PATH", - Usage: "Set configuration directory (config and keys)", + Name: "config", + Usage: "Set configuration directory (config and keys) to `PATH`", + }, + cli.StringFlag{ + Name: "data", + Usage: "Set data directory (database and logs) to `PATH`", }, } diff --git a/cmd/syncthing/cmdutil/util.go b/cmd/syncthing/cmdutil/util.go index 7c15f2995..6a44456b0 100644 --- a/cmd/syncthing/cmdutil/util.go +++ b/cmd/syncthing/cmdutil/util.go @@ -18,9 +18,9 @@ func SetConfigDataLocationsFromFlags(homeDir, confDir, dataDir string) error { dataSet := dataDir != "" switch { case dataSet != confSet: - return errors.New("either both or none of -conf and -data must be given, use -home to set both at once") + return errors.New("either both or none of --config and --data must be given, use --home to set both at once") case homeSet && dataSet: - return errors.New("-home must not be used together with -conf and -data") + return errors.New("--home must not be used together with --config and --data") case homeSet: confDir = homeDir dataDir = homeDir diff --git a/cmd/syncthing/decrypt/decrypt.go b/cmd/syncthing/decrypt/decrypt.go index 0247bb20f..119583dbd 100644 --- a/cmd/syncthing/decrypt/decrypt.go +++ b/cmd/syncthing/decrypt/decrypt.go @@ -45,7 +45,7 @@ func (c *CLI) Run() error { log.SetFlags(0) if c.To == "" && !c.VerifyOnly { - return fmt.Errorf("must set --to or --verify") + return fmt.Errorf("must set --to or --verify-only") } if c.TokenPath == "" { diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 00e2eef5d..b21273ab6 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -76,9 +76,9 @@ above). The value 0 is used to disable all of the above. The default is to show time only (2). Logging always happens to the command line (stdout) and optionally to the -file at the path specified by -logfile=path. In addition to an path, the special +file at the path specified by --logfile=path. In addition to an path, the special values "default" and "-" may be used. The former logs to DATADIR/syncthing.log -(see -data-dir), which is the default on Windows, and the latter only to stdout, +(see --data), which is the default on Windows, and the latter only to stdout, no file, which is the default anywhere else. diff --git a/lib/locations/locations.go b/lib/locations/locations.go index 3df0b877f..12077471a 100644 --- a/lib/locations/locations.go +++ b/lib/locations/locations.go @@ -40,10 +40,10 @@ const ( type BaseDirEnum string const ( - // Overridden by -home flag + // Overridden by --home flag ConfigBaseDir BaseDirEnum = "config" DataBaseDir BaseDirEnum = "data" - // User's home directory, *not* -home flag + // User's home directory, *not* --home flag UserHomeBaseDir BaseDirEnum = "userHome" LevelDBDir = "index-v0.14.0.db" @@ -98,7 +98,7 @@ var locationTemplates = map[LocationEnum]string{ HTTPSCertFile: "${config}/https-cert.pem", HTTPSKeyFile: "${config}/https-key.pem", Database: "${data}/" + LevelDBDir, - LogFile: "${data}/syncthing.log", // -logfile on Windows + LogFile: "${data}/syncthing.log", // --logfile on Windows CsrfTokens: "${data}/csrftokens.txt", PanicLog: "${data}/panic-${timestamp}.log", AuditLog: "${data}/audit-${timestamp}.log", diff --git a/lib/syncthing/utils.go b/lib/syncthing/utils.go index 3ddd6e569..660f856d1 100644 --- a/lib/syncthing/utils.go +++ b/lib/syncthing/utils.go @@ -90,7 +90,7 @@ func LoadConfigAtStartup(path string, cert tls.Certificate, evLogger events.Logg l.Infof("Now, THAT's what we call a config from the future! Don't worry. As long as you hit that wire with the connecting hook at precisely eighty-eight miles per hour the instant the lightning strikes the tower... everything will be fine.") } if originalVersion > config.CurrentVersion && !allowNewerConfig { - return nil, fmt.Errorf("config file version (%d) is newer than supported version (%d). If this is expected, use -allow-newer-config to override.", originalVersion, config.CurrentVersion) + return nil, fmt.Errorf("config file version (%d) is newer than supported version (%d). If this is expected, use --allow-newer-config to override.", originalVersion, config.CurrentVersion) } err = archiveAndSaveConfig(cfg, originalVersion) if err != nil { diff --git a/test/cli_test.go b/test/cli_test.go index f8e783893..c19d43831 100644 --- a/test/cli_test.go +++ b/test/cli_test.go @@ -31,7 +31,7 @@ func TestCLIReset(t *testing.T) { // Run reset to clean up - cmd := exec.Command("../bin/syncthing", "-no-browser", "-home", "h1", "-reset-database") + cmd := exec.Command("../bin/syncthing", "--no-browser", "--home", "h1", "--reset-database") cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout err := cmd.Run() @@ -63,9 +63,9 @@ func TestCLIGenerate(t *testing.T) { t.Fatal(err) } - // -generate should create a bunch of stuff + // --generate should create a bunch of stuff - cmd := exec.Command("../bin/syncthing", "-no-browser", "-generate", "home.out") + cmd := exec.Command("../bin/syncthing", "--no-browser", "--generate", "home.out") cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout err = cmd.Run() @@ -91,7 +91,7 @@ func TestCLIFirstStartup(t *testing.T) { // First startup should create config, BEP certificate, and HTTP certificate. - cmd := exec.Command("../bin/syncthing", "-no-browser", "-home", "home.out") + cmd := exec.Command("../bin/syncthing", "--no-browser", "--home", "home.out") cmd.Env = append(os.Environ(), "STNORESTART=1") cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout diff --git a/test/override_test.go b/test/override_test.go index a4af61bf5..b2fa14f11 100644 --- a/test/override_test.go +++ b/test/override_test.go @@ -199,7 +199,7 @@ func TestOverrideIgnores(t *testing.T) { log.Println("Starting sendOnly...") sendOnly := syncthingProcess{ // id1 instance: "1", - argv: []string{"-home", "h1"}, + argv: []string{"--home", "h1"}, port: 8081, apiKey: apiKey, } @@ -212,7 +212,7 @@ func TestOverrideIgnores(t *testing.T) { log.Println("Starting sendRecv...") sendRecv := syncthingProcess{ // id2 instance: "2", - argv: []string{"-home", "h2"}, + argv: []string{"--home", "h2"}, port: 8082, apiKey: apiKey, } diff --git a/test/util.go b/test/util.go index 38b00a5a7..8f69dacda 100644 --- a/test/util.go +++ b/test/util.go @@ -542,7 +542,7 @@ func startInstance(t *testing.T, i int) *rc.Process { p := rc.NewProcess(addr) p.LogTo(log) - if err := p.Start("../bin/syncthing", "-home", fmt.Sprintf("h%d", i), "-no-browser"); err != nil { + if err := p.Start("../bin/syncthing", "--home", fmt.Sprintf("h%d", i), "--no-browser"); err != nil { t.Fatal(err) } p.AwaitStartup()