diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-01-21 15:31:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-21 15:31:32 -0500 |
commit | 6fd83de31dab0c60932972c6b26f68fa0bd1871f (patch) | |
tree | d017ed4d59da4a0f0b703430d60b2d2f43484aaa /cmd/podman/volumes | |
parent | 3ba1a8de8649db2f5cdde80d0f4cf02370e10b8a (diff) | |
parent | 9d31fed5f75186f618e95ab7492ef6bc2b511d5f (diff) | |
download | podman-6fd83de31dab0c60932972c6b26f68fa0bd1871f.tar.gz podman-6fd83de31dab0c60932972c6b26f68fa0bd1871f.tar.bz2 podman-6fd83de31dab0c60932972c6b26f68fa0bd1871f.zip |
Merge pull request #9027 from Luap99/podman-volume-exists
Podman volume exists
Diffstat (limited to 'cmd/podman/volumes')
-rw-r--r-- | cmd/podman/volumes/exists.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/cmd/podman/volumes/exists.go b/cmd/podman/volumes/exists.go new file mode 100644 index 000000000..71cd117ae --- /dev/null +++ b/cmd/podman/volumes/exists.go @@ -0,0 +1,40 @@ +package volumes + +import ( + "github.com/containers/podman/v2/cmd/podman/common" + "github.com/containers/podman/v2/cmd/podman/registry" + "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/spf13/cobra" +) + +var ( + volumeExistsDescription = `If the given volume exists, podman volume exists exits with 0, otherwise the exit code will be 1.` + volumeExistsCommand = &cobra.Command{ + Use: "exists VOLUME", + Short: "volume exists", + Long: volumeExistsDescription, + RunE: volumeExists, + Example: `podman volume exists myvol`, + Args: cobra.ExactArgs(1), + ValidArgsFunction: common.AutocompleteVolumes, + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: volumeExistsCommand, + Parent: volumeCmd, + }) +} + +func volumeExists(cmd *cobra.Command, args []string) error { + response, err := registry.ContainerEngine().VolumeExists(registry.GetContext(), args[0]) + if err != nil { + return err + } + if !response.Value { + registry.SetExitCode(1) + } + return nil +} |