github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podman/autoupdate.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/containers/libpod/cmd/podman/cliconfig" 7 "github.com/containers/libpod/pkg/adapter" 8 "github.com/pkg/errors" 9 "github.com/spf13/cobra" 10 ) 11 12 var ( 13 autoUpdateCommand cliconfig.AutoUpdateValues 14 autoUpdateDescription = `Auto update containers according to their auto-update policy. 15 16 Auto-update policies are specified with the "io.containers.autoupdate" label.` 17 _autoUpdateCommand = &cobra.Command{ 18 Use: "auto-update [flags]", 19 Short: "Auto update containers according to their auto-update policy", 20 Args: noSubArgs, 21 Long: autoUpdateDescription, 22 RunE: func(cmd *cobra.Command, args []string) error { 23 restartCommand.InputArgs = args 24 restartCommand.GlobalFlags = MainGlobalOpts 25 return autoUpdateCmd(&restartCommand) 26 }, 27 Example: `podman auto-update`, 28 } 29 ) 30 31 func init() { 32 autoUpdateCommand.Command = _autoUpdateCommand 33 autoUpdateCommand.SetHelpTemplate(HelpTemplate()) 34 autoUpdateCommand.SetUsageTemplate(UsageTemplate()) 35 } 36 37 func autoUpdateCmd(c *cliconfig.RestartValues) error { 38 runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand) 39 if err != nil { 40 return errors.Wrapf(err, "error creating libpod runtime") 41 } 42 defer runtime.DeferredShutdown(false) 43 44 units, failures := runtime.AutoUpdate() 45 for _, unit := range units { 46 fmt.Println(unit) 47 } 48 var finalErr error 49 if len(failures) > 0 { 50 finalErr = failures[0] 51 for _, e := range failures[1:] { 52 finalErr = errors.Errorf("%v\n%v", finalErr, e) 53 } 54 } 55 return finalErr 56 }