1
0
Эх сурвалжийг харах

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
André Colomb 4 жил өмнө
parent
commit
41bfb7a330

+ 9 - 9
cmd/syncthing/cli/main.go

@@ -61,23 +61,23 @@ func Run() error {
 	fakeFlags := []cli.Flag{
 	fakeFlags := []cli.Flag{
 		cli.StringFlag{
 		cli.StringFlag{
 			Name:  "gui-address",
 			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{
 		cli.StringFlag{
 			Name:  "gui-apikey",
 			Name:  "gui-apikey",
-			Value: "API-KEY",
-			Usage: "Override GUI API key",
+			Usage: "Override GUI API key to `API-KEY`",
 		},
 		},
 		cli.StringFlag{
 		cli.StringFlag{
 			Name:  "home",
 			Name:  "home",
-			Value: "PATH",
-			Usage: "Set configuration and data directory",
+			Usage: "Set configuration and data directory to `PATH`",
 		},
 		},
 		cli.StringFlag{
 		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`",
 		},
 		},
 	}
 	}
 
 

+ 2 - 2
cmd/syncthing/cmdutil/util.go

@@ -18,9 +18,9 @@ func SetConfigDataLocationsFromFlags(homeDir, confDir, dataDir string) error {
 	dataSet := dataDir != ""
 	dataSet := dataDir != ""
 	switch {
 	switch {
 	case dataSet != confSet:
 	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:
 	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:
 	case homeSet:
 		confDir = homeDir
 		confDir = homeDir
 		dataDir = homeDir
 		dataDir = homeDir

+ 1 - 1
cmd/syncthing/decrypt/decrypt.go

@@ -45,7 +45,7 @@ func (c *CLI) Run() error {
 	log.SetFlags(0)
 	log.SetFlags(0)
 
 
 	if c.To == "" && !c.VerifyOnly {
 	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 == "" {
 	if c.TokenPath == "" {

+ 2 - 2
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).
 show time only (2).
 
 
 Logging always happens to the command line (stdout) and optionally to the
 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
 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.
 no file, which is the default anywhere else.
 
 
 
 

+ 3 - 3
lib/locations/locations.go

@@ -40,10 +40,10 @@ const (
 type BaseDirEnum string
 type BaseDirEnum string
 
 
 const (
 const (
-	// Overridden by -home flag
+	// Overridden by --home flag
 	ConfigBaseDir BaseDirEnum = "config"
 	ConfigBaseDir BaseDirEnum = "config"
 	DataBaseDir   BaseDirEnum = "data"
 	DataBaseDir   BaseDirEnum = "data"
-	// User's home directory, *not* -home flag
+	// User's home directory, *not* --home flag
 	UserHomeBaseDir BaseDirEnum = "userHome"
 	UserHomeBaseDir BaseDirEnum = "userHome"
 
 
 	LevelDBDir = "index-v0.14.0.db"
 	LevelDBDir = "index-v0.14.0.db"
@@ -98,7 +98,7 @@ var locationTemplates = map[LocationEnum]string{
 	HTTPSCertFile: "${config}/https-cert.pem",
 	HTTPSCertFile: "${config}/https-cert.pem",
 	HTTPSKeyFile:  "${config}/https-key.pem",
 	HTTPSKeyFile:  "${config}/https-key.pem",
 	Database:      "${data}/" + LevelDBDir,
 	Database:      "${data}/" + LevelDBDir,
-	LogFile:       "${data}/syncthing.log", // -logfile on Windows
+	LogFile:       "${data}/syncthing.log", // --logfile on Windows
 	CsrfTokens:    "${data}/csrftokens.txt",
 	CsrfTokens:    "${data}/csrftokens.txt",
 	PanicLog:      "${data}/panic-${timestamp}.log",
 	PanicLog:      "${data}/panic-${timestamp}.log",
 	AuditLog:      "${data}/audit-${timestamp}.log",
 	AuditLog:      "${data}/audit-${timestamp}.log",

+ 1 - 1
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.")
 			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 {
 		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)
 		err = archiveAndSaveConfig(cfg, originalVersion)
 		if err != nil {
 		if err != nil {

+ 4 - 4
test/cli_test.go

@@ -31,7 +31,7 @@ func TestCLIReset(t *testing.T) {
 
 
 	// Run reset to clean up
 	// 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.Stdout = os.Stdout
 	cmd.Stderr = os.Stdout
 	cmd.Stderr = os.Stdout
 	err := cmd.Run()
 	err := cmd.Run()
@@ -63,9 +63,9 @@ func TestCLIGenerate(t *testing.T) {
 		t.Fatal(err)
 		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.Stdout = os.Stdout
 	cmd.Stderr = os.Stdout
 	cmd.Stderr = os.Stdout
 	err = cmd.Run()
 	err = cmd.Run()
@@ -91,7 +91,7 @@ func TestCLIFirstStartup(t *testing.T) {
 
 
 	// First startup should create config, BEP certificate, and HTTP certificate.
 	// 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.Env = append(os.Environ(), "STNORESTART=1")
 	cmd.Stdout = os.Stdout
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stdout
 	cmd.Stderr = os.Stdout

+ 2 - 2
test/override_test.go

@@ -199,7 +199,7 @@ func TestOverrideIgnores(t *testing.T) {
 	log.Println("Starting sendOnly...")
 	log.Println("Starting sendOnly...")
 	sendOnly := syncthingProcess{ // id1
 	sendOnly := syncthingProcess{ // id1
 		instance: "1",
 		instance: "1",
-		argv:     []string{"-home", "h1"},
+		argv:     []string{"--home", "h1"},
 		port:     8081,
 		port:     8081,
 		apiKey:   apiKey,
 		apiKey:   apiKey,
 	}
 	}
@@ -212,7 +212,7 @@ func TestOverrideIgnores(t *testing.T) {
 	log.Println("Starting sendRecv...")
 	log.Println("Starting sendRecv...")
 	sendRecv := syncthingProcess{ // id2
 	sendRecv := syncthingProcess{ // id2
 		instance: "2",
 		instance: "2",
-		argv:     []string{"-home", "h2"},
+		argv:     []string{"--home", "h2"},
 		port:     8082,
 		port:     8082,
 		apiKey:   apiKey,
 		apiKey:   apiKey,
 	}
 	}

+ 1 - 1
test/util.go

@@ -542,7 +542,7 @@ func startInstance(t *testing.T, i int) *rc.Process {
 
 
 	p := rc.NewProcess(addr)
 	p := rc.NewProcess(addr)
 	p.LogTo(log)
 	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)
 		t.Fatal(err)
 	}
 	}
 	p.AwaitStartup()
 	p.AwaitStartup()