in pkg/question/question.go [128:176]
func AskRegion(h *ec2helper.EC2Helper) (*string, error) {
defaultRegion := h.Sess.Config.Region
regionDescription := getRegionDescriptions()
const regionPerRow = 1
const elementPerRegion = 3
// Get all enabled regions and make sure no error
regions, err := h.GetEnabledRegions()
if err != nil {
return nil, err
}
data := [][]string{}
indexedOptions := []string{}
// Fill the data used for drawing a table and the options map
var row []string
for index, region := range regions {
indexedOptions = append(indexedOptions, *region.RegionName)
if index%regionPerRow == 0 {
row = []string{}
}
row = append(row, fmt.Sprintf("%d.", index+1))
row = append(row, fmt.Sprintf("%s", *region.RegionName))
desc, found := (*regionDescription)[*region.RegionName]
if found {
row = append(row, desc)
}
// Append the row to the data when the row is filled with 4 elements
if len(row) == regionPerRow*elementPerRegion {
data = append(data, row)
}
}
optionsText := table.BuildTable(data, []string{"Option", "Region", "Description"})
question := "Region"
answer := AskQuestion(&AskQuestionInput{
QuestionString: question,
DefaultOption: defaultRegion,
OptionsString: &optionsText,
IndexedOptions: indexedOptions,
})
return &answer, nil
}