flatface.go: removed leading and trailing spaces from input

This commit is contained in:
mollusk 2018-01-03 02:19:47 -07:00
parent 0ccdfeaa40
commit 279e2d390d

View File

@ -6,6 +6,7 @@ import (
"log"
"os"
"os/exec"
"strings"
)
func input(s string) (string, error) {
@ -29,17 +30,19 @@ func searchRepo() {
var programName, _ = input(">> ")
if programName == "m" {
trimInput := strings.TrimSpace(programName)
if trimInput == "m" {
return
} else if programName == "q" {
} else if trimInput == "q" {
os.Exit(0)
} else {
cmd := exec.Command("flatpak", "search", programName)
cmd := exec.Command("flatpak", "search", trimInput)
out, err := cmd.CombinedOutput()
if err != nil {
searchRepo()
}
fmt.Print("\n", "Results for ", programName, ": \n\n", string(out), "\n")
fmt.Print("\n", "Results for ", trimInput, ": \n\n", string(out), "\n")
searchRepo()
}
}
@ -53,19 +56,18 @@ func installPak() {
print("NOTE: install can take several seconds and appear to hang. Please be patient...\n\n")
var programName, _ = input(">> ")
if programName == "m" {
trimInput := strings.TrimSpace(programName)
if trimInput == "m" {
return
} else if programName == "q" {
} else if trimInput == "q" {
os.Exit(0)
} else if programName == "" {
print("Please enter valid input\n")
installPak()
} else if programName == " " {
print("Please enter valid input")
installPak()
} else {
cmd := exec.Command("flatpak", "install", "-y", "flathub", programName)
cmd := exec.Command("flatpak", "install", "-y", "flathub", trimInput)
out, err := cmd.CombinedOutput()
if err != nil {
installPak()
}
@ -92,12 +94,14 @@ func removePak() {
print("Type: 'q' to quit the application\n\n")
var programName, _ = input(">> ")
if programName == "m" {
trimInput := strings.TrimSpace(programName)
if trimInput == "m" {
return
} else if programName == "q" {
} else if trimInput == "q" {
os.Exit(0)
} else {
cmd := exec.Command("flatpak", "uninstall", programName)
cmd := exec.Command("flatpak", "uninstall", trimInput)
out, err := cmd.CombinedOutput()
if err != nil {
removePak()
@ -163,18 +167,20 @@ func mainMenu() {
choice, _ = input(">> ")
if choice == "s" {
trimInput := strings.TrimSpace(choice)
if trimInput == "s" {
searchRepo()
} else if choice == "i" {
} else if trimInput == "i" {
installPak()
} else if choice == "r" {
} else if trimInput == "r" {
removePak()
} else if choice == "l" {
} else if trimInput == "l" {
listPak()
} else if choice == "u" {
} else if trimInput == "u" {
updatePak()
} else if choice == "q" {
} else if trimInput == "q" {
os.Exit(0)
} else {
print("Unknown option")