konveyor / move2kube

Move2Kube is a command-line tool for automating creation of Infrastructure as code (IaC) artifacts. It has inbuilt support for creating IaC artifacts for replatforming to Kubernetes/Openshift.
https://move2kube.konveyor.io/
Apache License 2.0
383 stars 118 forks source link

Reduce the chance of bugs and simplify the logic for certain QA by using indices instead of actual options. #274

Open HarikrishnanBalagopal opened 3 years ago

HarikrishnanBalagopal commented 3 years ago

Description

During Select and MultiSelect type QA we present some options to the user and they select one or more of them. To make it simple for the user we simplify the options (ex: make absolute paths into relative paths) However this can cause issues in certain corner cases where the options can become ambiguous.

It also limits us by not being able to show extra metadata that would be useful for the user. Ex: Display translation type next to the service name.

? 1. Select all services that are needed: 
Hints: 
 [The services unselected here will be ignored.]
  [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]
[✓] svc1 [Dockerfile2Kube]
[✓] svc2 [Compose2Kube]
[✓] svc3 [Any2Kube]

Proposed Fix

Use indices instead of strings. Ex:

package main
import (
    "fmt"
    "github.com/AlecAivazis/survey/v2"
)
func main() {
    days := []int{}
    prompt := &survey.MultiSelect{
        Message: "What days do you prefer:",
        Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
    }
    survey.AskOne(prompt, &days)
    fmt.Printf("days: %+v\n", days)
}

This allows us to display something nice to the user while using a different thing internally.

HarikrishnanBalagopal commented 3 years ago

Avoids chance for ambiguity here: https://github.com/konveyor/move2kube/blob/main/internal/move2kube/planner.go#L206-L216 once this is fixed.

ashokponkumar commented 3 years ago

We should probably add another text named say, display text instead of changing the current behavior, so more robust display engines like cli and web can use them. For things like settings, we can retain current behavior.

Indices need to rely on orders which will be a challenge.

https://www.w3schools.com/tags/tag_select.asp