flatface.go: removed leading and trailing spaces from input
This commit is contained in:
parent
0ccdfeaa40
commit
279e2d390d
50
flatface.go
50
flatface.go
@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func input(s string) (string, error) {
|
func input(s string) (string, error) {
|
||||||
@ -29,17 +30,19 @@ func searchRepo() {
|
|||||||
|
|
||||||
var programName, _ = input(">> ")
|
var programName, _ = input(">> ")
|
||||||
|
|
||||||
if programName == "m" {
|
trimInput := strings.TrimSpace(programName)
|
||||||
|
|
||||||
|
if trimInput == "m" {
|
||||||
return
|
return
|
||||||
} else if programName == "q" {
|
} else if trimInput == "q" {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
} else {
|
||||||
cmd := exec.Command("flatpak", "search", programName)
|
cmd := exec.Command("flatpak", "search", trimInput)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
searchRepo()
|
searchRepo()
|
||||||
}
|
}
|
||||||
fmt.Print("\n", "Results for ", programName, ": \n\n", string(out), "\n")
|
fmt.Print("\n", "Results for ", trimInput, ": \n\n", string(out), "\n")
|
||||||
searchRepo()
|
searchRepo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,19 +56,18 @@ func installPak() {
|
|||||||
print("NOTE: install can take several seconds and appear to hang. Please be patient...\n\n")
|
print("NOTE: install can take several seconds and appear to hang. Please be patient...\n\n")
|
||||||
var programName, _ = input(">> ")
|
var programName, _ = input(">> ")
|
||||||
|
|
||||||
if programName == "m" {
|
trimInput := strings.TrimSpace(programName)
|
||||||
|
|
||||||
|
if trimInput == "m" {
|
||||||
return
|
return
|
||||||
} else if programName == "q" {
|
|
||||||
|
} else if trimInput == "q" {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else if programName == "" {
|
|
||||||
print("Please enter valid input\n")
|
|
||||||
installPak()
|
|
||||||
} else if programName == " " {
|
|
||||||
print("Please enter valid input")
|
|
||||||
installPak()
|
|
||||||
} else {
|
} else {
|
||||||
cmd := exec.Command("flatpak", "install", "-y", "flathub", programName)
|
cmd := exec.Command("flatpak", "install", "-y", "flathub", trimInput)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
installPak()
|
installPak()
|
||||||
}
|
}
|
||||||
@ -92,12 +94,14 @@ func removePak() {
|
|||||||
print("Type: 'q' to quit the application\n\n")
|
print("Type: 'q' to quit the application\n\n")
|
||||||
var programName, _ = input(">> ")
|
var programName, _ = input(">> ")
|
||||||
|
|
||||||
if programName == "m" {
|
trimInput := strings.TrimSpace(programName)
|
||||||
|
|
||||||
|
if trimInput == "m" {
|
||||||
return
|
return
|
||||||
} else if programName == "q" {
|
} else if trimInput == "q" {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
} else {
|
||||||
cmd := exec.Command("flatpak", "uninstall", programName)
|
cmd := exec.Command("flatpak", "uninstall", trimInput)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
removePak()
|
removePak()
|
||||||
@ -163,18 +167,20 @@ func mainMenu() {
|
|||||||
|
|
||||||
choice, _ = input(">> ")
|
choice, _ = input(">> ")
|
||||||
|
|
||||||
if choice == "s" {
|
trimInput := strings.TrimSpace(choice)
|
||||||
|
|
||||||
|
if trimInput == "s" {
|
||||||
searchRepo()
|
searchRepo()
|
||||||
|
|
||||||
} else if choice == "i" {
|
} else if trimInput == "i" {
|
||||||
installPak()
|
installPak()
|
||||||
} else if choice == "r" {
|
} else if trimInput == "r" {
|
||||||
removePak()
|
removePak()
|
||||||
} else if choice == "l" {
|
} else if trimInput == "l" {
|
||||||
listPak()
|
listPak()
|
||||||
} else if choice == "u" {
|
} else if trimInput == "u" {
|
||||||
updatePak()
|
updatePak()
|
||||||
} else if choice == "q" {
|
} else if trimInput == "q" {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
} else {
|
||||||
print("Unknown option")
|
print("Unknown option")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user