package main import ( "fmt" "os/exec" ) func checkPackageExists(pac string) bool { command := fmt.Sprintf("pacman -Qqe %s", pac) cmd:= exec.Command(command) err:=cmd.Run() if err != nil { return false; } return true; } func installPackage(pac string) { fmt.Printf("[PACMAN] Installing `%s`\n", pac) } func removePackage(pac string){ fmt.Printf("[PACMAN] Removing `%s`\n", pac) } func pacman(m interface{}) error { data, ok := m.(map[string]interface{}) if !ok { return fmt.Errorf("expected map[string]interface{}, got %T", m) } shouldPresent := false if data["state"] == "present" { shouldPresent = true } else if data["state"] == "absent"{ shouldPresent = false } pac := data["name"] if checkPackageExists(pac.(string)) { if shouldPresent { fmt.Printf("[PACMAN] `%s` Exists Skipping\n", pac) } else { removePackage(pac.(string)) } } else { if shouldPresent { installPackage(pac.(string)) } else { fmt.Printf("[PACMAN] `%s` doesn't exist skipping\n", pac) } } return nil }