This commit is contained in:
2021-04-11 13:04:11 +02:00
parent 43244302be
commit 335724cce7
12 changed files with 315 additions and 34 deletions

View File

@@ -39,25 +39,18 @@ var backupCmd = &cobra.Command{
}
defer lock.Unlock()
{
backup(internal.GetAllOrLocation(cmd, false), config)
selected, err := internal.GetAllOrSelected(cmd, false)
cobra.CheckErr(err)
for _, name := range selected {
location := config.Locations[name]
fmt.Printf("Backing up: `%s`", name)
location.Backup()
}
}
},
}
func init() {
rootCmd.AddCommand(backupCmd)
backupCmd.PersistentFlags().StringSliceP("location", "l", []string{}, "Locations")
backupCmd.PersistentFlags().BoolP("all", "a", false, "Backup all locations")
}
func backup(locations []string, config *internal.Config) {
for _, name := range locations {
location, ok := config.Locations[name]
if !ok {
fmt.Println(fmt.Errorf("location `%s` does not exist", name))
} else {
fmt.Printf("Backing up: `%s`", name)
location.Backup()
}
}
internal.AddFlagsToCommand(backupCmd, false)
}