mirror of
https://github.com/Baipyrus/ProxySwitcher.git
synced 2024-12-25 12:11:46 +00:00
prompting for command variants in config
This commit is contained in:
parent
9d304b862c
commit
4b72f228d3
@ -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
78
util/util.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user