53 lines
1018 B
Go
53 lines
1018 B
Go
package subtasks
|
|
|
|
import (
|
|
"fmt"
|
|
"io/fs"
|
|
"ocl/portainer-devtool/configs"
|
|
"ocl/portainer-devtool/tasks/common"
|
|
"ocl/portainer-devtool/utils"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
type ListVolumeSubTask struct {
|
|
common.GeneralTask
|
|
}
|
|
|
|
func NewListVolumeSubTask(cfg *configs.Config) *ListVolumeSubTask {
|
|
return &ListVolumeSubTask{
|
|
GeneralTask: *common.NewGeneralTask(cfg),
|
|
}
|
|
}
|
|
|
|
func (task *ListVolumeSubTask) Execute() error {
|
|
utils.HighlightPrint(fmt.Sprintf("Volume path: %s", task.Config.VolumePath))
|
|
|
|
volumeList := []string{" "}
|
|
filepath.WalkDir(task.Config.VolumePath, func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if path == task.Config.VolumePath {
|
|
return nil
|
|
}
|
|
|
|
if d.IsDir() {
|
|
if utils.MatchPathLength(task.Config.VolumePath, path, 1) {
|
|
volumeList = append(volumeList, d.Name())
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
|
|
utils.SuccessPrint(strings.Join(volumeList, "\n"))
|
|
|
|
return nil
|
|
}
|
|
|
|
func (task *ListVolumeSubTask) String() string {
|
|
return "List Volumes"
|
|
}
|