aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-01-21 15:31:32 -0500
committerGitHub <noreply@github.com>2021-01-21 15:31:32 -0500
commit6fd83de31dab0c60932972c6b26f68fa0bd1871f (patch)
treed017ed4d59da4a0f0b703430d60b2d2f43484aaa /cmd
parent3ba1a8de8649db2f5cdde80d0f4cf02370e10b8a (diff)
parent9d31fed5f75186f618e95ab7492ef6bc2b511d5f (diff)
downloadpodman-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')
-rw-r--r--cmd/podman/volumes/exists.go40
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
+}