2020-11-17 05:41:34 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.jolheiser.com/tmpl/cmd/flags"
|
|
|
|
"go.jolheiser.com/tmpl/registry"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"go.jolheiser.com/beaver"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Update = &cli.Command{
|
|
|
|
Name: "update",
|
|
|
|
Usage: "Update a template",
|
|
|
|
Description: "Update a template in the registry from the original source",
|
2020-11-22 05:25:24 +00:00
|
|
|
ArgsUsage: "[name]",
|
2020-11-17 05:41:34 +00:00
|
|
|
Action: runUpdate,
|
|
|
|
}
|
|
|
|
|
|
|
|
func runUpdate(ctx *cli.Context) error {
|
|
|
|
if ctx.NArg() < 1 {
|
2020-11-22 05:25:24 +00:00
|
|
|
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
2020-11-17 05:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reg, err := registry.Open(flags.Registry)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpl, err := reg.GetTemplate(ctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-30 05:16:25 +00:00
|
|
|
if err := reg.UpdateTemplate(tmpl.Name); err != nil {
|
2020-11-17 05:41:34 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
beaver.Infof("Successfully updated %s", tmpl.Name)
|
|
|
|
return nil
|
|
|
|
}
|