Commit 9b4fbaca authored by daumens's avatar daumens

confirm before return to menu, add commands

parent 360913c6
......@@ -34,7 +34,7 @@ func mainMenu() {
execCommandInteractive("echo ''")
menuItems := []menuItem{
{Number: 1, Name: "Update System", Description: "Update all installed packages", Symbol: "\U00002B6E", AurRequired: false},
{Number: 2, Name: "Clean System", Description: "", Symbol: "\U00002714", AurRequired: false},
{Number: 2, Name: "Clean System", Description: "Remove unneeded/orphaned packages", Symbol: "\U00002714", AurRequired: false},
{Number: 3, Name: "Install Package", Description: "Search and install a new package", Symbol: "\U0001F81B", AurRequired: false},
{Number: 4, Name: "Remove Package + Deps", Description: "Remove an installed package and its (no longer used) dependencies", Symbol: "\U00002718", AurRequired: false},
{Number: 5, Name: "Package Information", Description: "Search for a package (installed or not) and display information about it", Symbol: "\U00002139", AurRequired: false},
......@@ -86,27 +86,27 @@ func mainMenu() {
switch index {
case 0:
updatePackages()
time.Sleep(1 * time.Second)
case 1:
fmt.Println("Starting system update...")
cleanPackages()
case 2:
installPackage()
time.Sleep(1 * time.Second)
case 3:
removePackage()
time.Sleep(1 * time.Second)
case 4:
packageInfo()
case 5:
packageFiles()
case 6:
fmt.Println("Starting system update...")
dependencyTree(false)
case 7:
fmt.Println("Starting system update...")
dependencyTree(true)
case len(menuItems) - 1:
fmt.Println(color.Purple(" o/ byebye.."))
return
}
time.Sleep(1 * time.Second)
// wait for confirmation and return to mainMenu
execCommandInteractive("read -n 1 -s -r -p 'Press any key to return to menu...'")
mainMenu()
}
......@@ -131,7 +131,7 @@ func installPackage() {
if err != nil {
fmt.Printf("Install failed: %s\n", err)
}
execCommandInteractive("echo '" + color.Green("OK!") + "'")
execCommandInteractive("echo '" + color.Green("Installation OK!") + "'")
}
func removePackage() {
......@@ -146,7 +146,7 @@ func removePackage() {
if err != nil {
fmt.Printf("Install failed: %s\n", err)
}
execCommandInteractive("echo '" + color.Green("OK!") + "'")
execCommandInteractive("echo '" + color.Green("Deinstallation OK!") + "'")
}
func packageInfo() {
......@@ -156,7 +156,11 @@ func packageInfo() {
fmt.Printf("Selection failed: %s\n", err)
return
}
err = execCommandInteractive("sudo pacman -Qii " + pkg.Name)
if pkg.Installed {
err = execCommandInteractive("sudo pacman -Qii " + pkg.Name)
} else {
err = execCommandInteractive("sudo pacman -Sii " + pkg.Name)
}
if err != nil {
fmt.Printf("Install failed: %s\n", err)
......@@ -178,6 +182,33 @@ func packageFiles() {
execCommandInteractive("echo '" + color.Green("OK!") + "'")
}
func dependencyTree(reverse bool) {
pkg, err := pacselect.SelectFromInstalled(true)
if err != nil {
fmt.Printf("Selection failed: %s\n", err)
return
}
if !reverse {
err = execCommandInteractive("pactree " + pkg.Name)
} else {
err = execCommandInteractive("pactree -r " + pkg.Name)
}
if err != nil {
fmt.Printf("Dependency tree failed: %s\n", err)
}
execCommandInteractive("echo '" + color.Green("OK!") + "'")
}
func cleanPackages() {
err := execCommandInteractive("sudo pacman -Rns $(pacman -Qdtq)")
if err != nil {
fmt.Printf(color.Red("Update failed:")+" %s\n", err)
}
execCommandInteractive("echo '" + color.Green("Clean System OK!") + "'")
}
func execCommandInteractive(str string) error {
cmd := exec.Command("/bin/sh", "-c", str)
cmd.Stdin = os.Stdin
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment