2020-11-30 05:16:25 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"go.jolheiser.com/tmpl/cmd/flags"
|
|
|
|
"go.jolheiser.com/tmpl/registry"
|
|
|
|
|
2021-11-02 03:22:27 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2020-11-30 05:16:25 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Restore = &cli.Command{
|
|
|
|
Name: "restore",
|
|
|
|
Usage: "Restore missing templates",
|
|
|
|
Description: "Restore templates that are listed in the registry, but are missing archives",
|
|
|
|
Action: runRestore,
|
|
|
|
}
|
|
|
|
|
|
|
|
func runRestore(_ *cli.Context) error {
|
|
|
|
reg, err := registry.Open(flags.Registry)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var num int
|
|
|
|
for _, tmpl := range reg.Templates {
|
|
|
|
if _, err := os.Lstat(tmpl.ArchivePath()); os.IsNotExist(err) {
|
2021-11-02 03:22:27 +00:00
|
|
|
log.Info().Msgf("Restoring %q...", tmpl.Name)
|
2020-11-30 05:16:25 +00:00
|
|
|
if err := reg.UpdateTemplate(tmpl.Name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
num++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 03:22:27 +00:00
|
|
|
log.Info().Int("count", num).Msgf("Restored templates.")
|
2020-11-30 05:16:25 +00:00
|
|
|
return nil
|
|
|
|
}
|