2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-06 02:50:50 +00:00

Improve migrate command

This commit is contained in:
Alexander Neumann 2022-03-31 21:11:56 +02:00 committed by Michael Eischer
parent 92816fa966
commit 3af6c180e4

View File

@ -8,11 +8,12 @@ import (
) )
var cmdMigrate = &cobra.Command{ var cmdMigrate = &cobra.Command{
Use: "migrate [flags] [name]", Use: "migrate [flags] [migration name] [...]",
Short: "Apply migrations", Short: "Apply migrations",
Long: ` Long: `
The "migrate" command applies migrations to a repository. When no migration The "migrate" command checks which migrations can be applied for a repository
name is explicitly given, a list of migrations that can be applied is printed. and prints a list with available migration names. If one or more migration
names are specified, these migrations are applied.
EXIT STATUS EXIT STATUS
=========== ===========
@ -41,6 +42,8 @@ func init() {
func checkMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repository) error { func checkMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repository) error {
ctx := gopts.ctx ctx := gopts.ctx
Printf("available migrations:\n") Printf("available migrations:\n")
found := false
for _, m := range migrations.All { for _, m := range migrations.All {
ok, err := m.Check(ctx, repo) ok, err := m.Check(ctx, repo)
if err != nil { if err != nil {
@ -48,10 +51,15 @@ func checkMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repos
} }
if ok { if ok {
Printf(" %v: %v\n", m.Name(), m.Desc()) Printf(" %v\t%v\n", m.Name(), m.Desc())
found = true
} }
} }
if !found {
Printf("no migrations found")
}
return nil return nil
} }