aboutsummaryrefslogtreecommitdiff
path: root/test/testvol/list.go
blob: fea615a704f454aab8d83c4c6be9a5bd23769a62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"fmt"

	"github.com/spf13/cobra"
)

var listCmd = &cobra.Command{
	Use:   "list",
	Short: "list all volumes",
	Long:  `List all volumes from the volume plugin listening on --sock-name`,
	Args:  cobra.NoArgs,
	RunE: func(cmd *cobra.Command, args []string) error {
		return listVol(config.sockName)
	},
}

func listVol(sockName string) error {
	plugin, err := getPlugin(sockName)
	if err != nil {
		return err
	}
	vols, err := plugin.ListVolumes()
	if err != nil {
		return err
	}
	for _, vol := range vols {
		fmt.Println(vol.Name)
	}
	return nil
}