github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podmanV2/pods/exists.go (about) 1 package pods 2 3 import ( 4 "context" 5 "os" 6 7 "github.com/containers/libpod/cmd/podmanV2/registry" 8 "github.com/containers/libpod/pkg/domain/entities" 9 "github.com/spf13/cobra" 10 ) 11 12 var ( 13 podExistsDescription = `If the named pod exists in local storage, podman pod exists exits with 0, otherwise the exit code will be 1.` 14 15 existsCommand = &cobra.Command{ 16 Use: "exists POD", 17 Short: "Check if a pod exists in local storage", 18 Long: podExistsDescription, 19 RunE: exists, 20 Args: cobra.ExactArgs(1), 21 Example: `podman pod exists podID 22 podman pod exists mypod || podman pod create --name mypod`, 23 } 24 ) 25 26 func init() { 27 registry.Commands = append(registry.Commands, registry.CliCommand{ 28 Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, 29 Command: existsCommand, 30 Parent: podCmd, 31 }) 32 } 33 34 func exists(cmd *cobra.Command, args []string) error { 35 response, err := registry.ContainerEngine().PodExists(context.Background(), args[0]) 36 if err != nil { 37 return err 38 } 39 if !response.Value { 40 os.Exit(1) 41 } 42 return nil 43 }