package main import ( "bufio" "fmt" "log" "os" "os/exec" ) func input(s string) (string, error) { stdin_buf := bufio.NewReader(os.Stdin) fmt.Print(s) text, err := stdin_buf.ReadString('\n') if err != nil { panic(err) } return text[:len(text)-1], err } func searchRepo() { var programName, _ = input("Name of search: ") cmd := exec.Command("flatpak", "search", programName) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print("\n", "Results for ", programName, ": \n\n", string(out), "\n") } func installPak() { var programName, _ = input("Install: ") cmd := exec.Command("flatpak", "install", "flathub", programName) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print("\n", "Results for ", programName, ": \n\n", string(out), "\n") } func removePak() { var programName, _ = input("Uninstall: ") cmd := exec.Command("flatpak", "uninstall", programName) out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print("\n", "Results for ", programName, ": \n\n", string(out), "\n\n") } func listPak() { cmd := exec.Command("flatpak", "list") out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print("\n", "Results for ", ": \n\n", string(out), "\n\n") } //// TODO /* func optionsMenu() { var choice string print("\n| FlatFace Options |\n\n") print("\n1. Add Repository\n\n") choice, _ = input(">> ") if choice == "1" { } } */ func updatePak() { cmd := exec.Command("flatpak", "update", "--appstream") out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print(string(out)) } func checkRepo() { print("\nSyncing repos...\n") cmd := exec.Command("flatpak", "remote-add", "--if-not-exists", "flathub", "https://flathub.org/repo/flathub.flatpakrepo") out, err := cmd.CombinedOutput() updatePak() if err != nil { log.Fatalf("cmd.Run() failed with %s\n", err) } fmt.Print(string(out)) } func mainMenu() { print("\n\n| FlatFace v0.0.1a |\n\n") var choice string print("1. Search remote for flatpaks\n") print("2. Install flatpaks from remote\n") print("3. Uninstall local flatpaks\n") print("4. List install flatpaks\n") print("5. Update\n") print("q. Quit\n\n") choice, _ = input(">> ") if choice == "1" { searchRepo() } else if choice == "2" { installPak() } else if choice == "3" { removePak() } else if choice == "4" { listPak() } else if choice == "5" { updatePak() } else if choice == "q" { os.Exit(1) } else { print("Unknown option") } } func main() { checkRepo() for { mainMenu() } }