prompting for command variants in config

This commit is contained in:
Baipyrus 2024-08-31 21:13:46 +02:00
parent 9d304b862c
commit 4b72f228d3
2 changed files with 84 additions and 0 deletions

View File

@ -22,6 +22,12 @@ var saveCmd = &cobra.Command{
fmt.Print("Command? ")
fmt.Scanln(&command)
fmt.Println("\nPrompting 'set' variants:")
set := util.PromptVariants()
fmt.Println("\nPrompting 'unset' variants:")
unset := util.PromptVariants()
config := util.Config{Name: name, Cmd: command, Set: set, Unset: unset}
fmt.Println("\n\nPlease confirm the following data:")

78
util/util.go Normal file
View File

@ -0,0 +1,78 @@
package util
import (
"fmt"
"strings"
)
func promptArguments() []string {
var args []string = []string{}
var count int
argumentLoop:
for true {
var arg string
fmt.Printf("Arg #%d? ", count+1)
fmt.Scanln(&arg)
if arg == "" {
break argumentLoop
}
args = append(args, arg)
count++
}
return args
}
func promptType() VariantType {
var variantType VariantType
typeLoop:
for true {
var input string
fmt.Print("Type? ")
fmt.Scanln(&input)
switch strings.ToLower(input) {
case "":
variantType = TEXT
break typeLoop
case "variable":
variantType = VARIABLE
break typeLoop
default:
fmt.Println("Given input not convertable to type!")
}
}
return variantType
}
func PromptVariants() []*Variant {
var variants []*Variant
var count int
variantLoop:
for true {
fmt.Printf("Prompting 'args' for variant #%d:\n", count+1)
args := promptArguments()
var equator string
fmt.Print("Equator? ")
fmt.Scanln(&equator)
if strings.ToLower(equator) == "skip" {
break variantLoop
}
variantType := promptType()
variant := Variant{Arguments: args, Type: variantType, Equator: equator}
variants = append(variants, &variant)
count++
}
return variants
}