package subtasks

import (
	"ocl/portainer-devtool/configs"
	"ocl/portainer-devtool/utils"
	"strings"
)

type ListRepositorySubTask struct {
	Config *configs.Config
}

func NewListRepositorySubTask(cfg *configs.Config) *ListRepositorySubTask {
	return &ListRepositorySubTask{
		Config: cfg,
	}
}

func (task *ListRepositorySubTask) Execute() error {
	utils.InputPrint("Which repository?")

	repositoryList := []string{" "}
	for _, repo := range task.Config.RepositoryConfig {
		repositoryList = append(repositoryList, repo.Name)
	}

	utils.SuccessPrint(strings.Join(repositoryList, "\n"))

	return nil
}

func (task *ListRepositorySubTask) String() string {
	return "List Repositories"
}
