Prevent user from specifying replica URL & config flag
Previously, if a replica URL was specified then the `-config` flag was silently ignored. This commit changes this behavior so that specifying both the URL & config flag will now return an error.
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -17,9 +16,8 @@ type WALCommand struct{}
|
||||
|
||||
// Run executes the command.
|
||||
func (c *WALCommand) Run(ctx context.Context, args []string) (err error) {
|
||||
var configPath string
|
||||
fs := flag.NewFlagSet("litestream-wal", flag.ContinueOnError)
|
||||
registerConfigFlag(fs, &configPath)
|
||||
configPath := registerConfigFlag(fs)
|
||||
replicaName := fs.String("replica", "", "replica name")
|
||||
generation := fs.String("generation", "", "generation name")
|
||||
fs.Usage = c.Usage
|
||||
@@ -34,12 +32,19 @@ func (c *WALCommand) Run(ctx context.Context, args []string) (err error) {
|
||||
var db *litestream.DB
|
||||
var r litestream.Replica
|
||||
if isURL(fs.Arg(0)) {
|
||||
if *configPath != "" {
|
||||
return fmt.Errorf("cannot specify a replica URL and the -config flag")
|
||||
}
|
||||
if r, err = NewReplicaFromConfig(&ReplicaConfig{URL: fs.Arg(0)}, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if configPath != "" {
|
||||
} else {
|
||||
if *configPath == "" {
|
||||
*configPath = DefaultConfigPath()
|
||||
}
|
||||
|
||||
// Load configuration.
|
||||
config, err := ReadConfigFile(configPath)
|
||||
config, err := ReadConfigFile(*configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -59,8 +64,6 @@ func (c *WALCommand) Run(ctx context.Context, args []string) (err error) {
|
||||
return fmt.Errorf("replica %q not found for database %q", *replicaName, db.Path())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return errors.New("config path or replica URL required")
|
||||
}
|
||||
|
||||
// Find WAL files by db or replica.
|
||||
|
||||
Reference in New Issue
Block a user