diff --git a/cmd/restic/global.go b/cmd/restic/global.go index cd17dccc7..4576a5fef 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -11,21 +11,12 @@ import ( "time" "github.com/restic/restic/internal/backend" - "github.com/restic/restic/internal/backend/azure" - "github.com/restic/restic/internal/backend/b2" "github.com/restic/restic/internal/backend/cache" - "github.com/restic/restic/internal/backend/gs" "github.com/restic/restic/internal/backend/limiter" - "github.com/restic/restic/internal/backend/local" "github.com/restic/restic/internal/backend/location" "github.com/restic/restic/internal/backend/logger" - "github.com/restic/restic/internal/backend/rclone" - "github.com/restic/restic/internal/backend/rest" "github.com/restic/restic/internal/backend/retry" - "github.com/restic/restic/internal/backend/s3" "github.com/restic/restic/internal/backend/sema" - "github.com/restic/restic/internal/backend/sftp" - "github.com/restic/restic/internal/backend/swift" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/options" "github.com/restic/restic/internal/repository" @@ -174,20 +165,6 @@ func (opts *GlobalOptions) PreRun(needsPassword bool) error { return nil } -func collectBackends() *location.Registry { - backends := location.NewRegistry() - backends.Register(azure.NewFactory()) - backends.Register(b2.NewFactory()) - backends.Register(gs.NewFactory()) - backends.Register(local.NewFactory()) - backends.Register(rclone.NewFactory()) - backends.Register(rest.NewFactory()) - backends.Register(s3.NewFactory()) - backends.Register(sftp.NewFactory()) - backends.Register(swift.NewFactory()) - return backends -} - // resolvePassword determines the password to be used for opening the repository. func resolvePassword(opts *GlobalOptions, envStr string) (string, error) { if opts.PasswordFile != "" && opts.PasswordCommand != "" { diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 2a8fec61a..a4c7bdd38 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -14,6 +14,7 @@ import ( "testing" "github.com/restic/restic/internal/backend" + "github.com/restic/restic/internal/backend/all" "github.com/restic/restic/internal/backend/retry" "github.com/restic/restic/internal/data" "github.com/restic/restic/internal/errors" @@ -218,7 +219,7 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) { // replace this hook with "nil" if listing a filetype more than once is necessary backendTestHook: func(r backend.Backend) (backend.Backend, error) { return newOrderedListOnceBackend(r), nil }, // start with default set of backends - backends: collectBackends(), + backends: all.Backends(), } cleanup = func() { diff --git a/cmd/restic/main.go b/cmd/restic/main.go index 43e1f0b7a..8579cfa5d 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -14,6 +14,7 @@ import ( "github.com/spf13/cobra" "go.uber.org/automaxprocs/maxprocs" + "github.com/restic/restic/internal/backend/all" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/feature" @@ -173,7 +174,7 @@ func main() { version, runtime.Version(), runtime.GOOS, runtime.GOARCH) globalOptions := GlobalOptions{ - backends: collectBackends(), + backends: all.Backends(), } func() { term, cancel := termstatus.Setup(os.Stdin, os.Stdout, os.Stderr, globalOptions.Quiet) diff --git a/internal/backend/all/all.go b/internal/backend/all/all.go new file mode 100644 index 000000000..c71acb00d --- /dev/null +++ b/internal/backend/all/all.go @@ -0,0 +1,28 @@ +package all + +import ( + "github.com/restic/restic/internal/backend/azure" + "github.com/restic/restic/internal/backend/b2" + "github.com/restic/restic/internal/backend/gs" + "github.com/restic/restic/internal/backend/local" + "github.com/restic/restic/internal/backend/location" + "github.com/restic/restic/internal/backend/rclone" + "github.com/restic/restic/internal/backend/rest" + "github.com/restic/restic/internal/backend/s3" + "github.com/restic/restic/internal/backend/sftp" + "github.com/restic/restic/internal/backend/swift" +) + +func Backends() *location.Registry { + backends := location.NewRegistry() + backends.Register(azure.NewFactory()) + backends.Register(b2.NewFactory()) + backends.Register(gs.NewFactory()) + backends.Register(local.NewFactory()) + backends.Register(rclone.NewFactory()) + backends.Register(rest.NewFactory()) + backends.Register(s3.NewFactory()) + backends.Register(sftp.NewFactory()) + backends.Register(swift.NewFactory()) + return backends +}