ledo/app/modules/interact/mode.go

32 lines
681 B
Go
Raw Normal View History

2021-10-21 00:51:32 +00:00
package interact
import (
survey "github.com/AlecAivazis/survey/v2"
"github.com/thoas/go-funk"
"ledo/app/modules/context"
)
func SelectMode(context *context.LedoContext, selectedMode string) (string, error) {
mode := context.Mode
if selectedMode == "" {
availableModes := mode.GetModes()
// the questions to ask
var qs = []*survey.Question{
{
Name: "providers",
Prompt: &survey.Select{
Message: "Select run mode",
PageSize: 10,
Options: funk.Keys(availableModes).([]string),
},
},
}
err := survey.Ask(qs, &selectedMode)
if err != nil {
return "", err
}
}
_, err := mode.SetMode(selectedMode)
return selectedMode, err
}