Changes, non compiling

This commit is contained in:
Jguer 2016-11-29 02:21:20 +00:00
parent 6e0830ce3b
commit 84de22df45
3 changed files with 18 additions and 109 deletions

View File

@ -1,4 +1,4 @@
package main
package yay
import (
"bufio"

View File

@ -1,92 +0,0 @@
package main
import (
"fmt"
"os"
"github.com/jguer/yay"
)
func usage() {
fmt.Println(`usage: yay <operation> [...]
operations:
yay {-h --help}
yay {-V --version}
yay {-D --database} <options> <package(s)>
yay {-F --files} [options] [package(s)]
yay {-Q --query} [options] [package(s)]
yay {-R --remove} [options] <package(s)>
yay {-S --sync} [options] [package(s)]
yay {-T --deptest} [options] [package(s)]
yay {-U --upgrade} [options] <file(s)>
New operations:
yay -Qstats - Displays system information
`)
}
func parser() (op string, options []string, packages []string, err error) {
if len(os.Args) < 2 {
err = fmt.Errorf("no operation specified")
return
}
for _, arg := range os.Args[1:] {
if arg[0] == '-' && arg[1] != '-' {
op = arg
}
if arg[0] == '-' && arg[1] == '-' {
if arg == "--help" {
op = arg
}
options = append(options, arg)
}
if arg[0] != '-' {
packages = append(packages, arg)
}
}
if op == "" {
op = "yogurt"
}
return
}
func main() {
op, options, pkgs, err := parser()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
switch op {
case "-Qstats":
err = yay.LocalStatistics()
case "-Ss":
for _, pkg := range pkgs {
err = searchMode(pkg, &conf)
}
case "-S":
err = InstallPackage(pkgs, &conf, options)
case "-Syu", "-Suy":
err = yay.Upgrade(options)
case "yogurt":
for _, pkg := range pkgs {
err = yay.NumberMenu(pkg, &conf, options)
break
}
case "--help", "-h":
usage()
default:
err = passToPacman(op, pkgs, options)
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}

View File

@ -1,4 +1,4 @@
package main
package yay
import (
"fmt"
@ -26,10 +26,10 @@ type Result struct {
// PacmanConf describes the default pacman config file
const PacmanConf string = "/etc/pacman.conf"
var conf *alpm.PacmanConfig
var conf alpm.PacmanConfig
func init() {
*conf, _ = readConfig(PacmanConf)
conf, _ = readConfig(PacmanConf)
}
func readConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
@ -67,8 +67,8 @@ func SearchRepos(pkgName string, conf *alpm.PacmanConfig, mode int) (err error)
if err != nil {
}
dbList, err := h.SyncDbs()
localdb, err := h.LocalDb()
dbList, _ := h.SyncDbs()
localdb, _ := h.LocalDb()
var installed bool
var i int
@ -82,16 +82,16 @@ func SearchRepos(pkgName string, conf *alpm.PacmanConfig, mode int) (err error)
}
switch {
case mode != SearchMode && installed == true:
case mode != SearchMode && !installed:
fmt.Printf("%d \x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[32;40mInstalled\x1b[0m\n%s\n",
i, db.Name(), pkg.Name(), pkg.Version(), pkg.Description())
case mode != SearchMode && installed != true:
case mode != SearchMode && !installed:
fmt.Printf("%d \x1b[1m%s/\x1b[33m%s \x1b[36m%s\x1b[0m\n%s\n",
i, db.Name(), pkg.Name(), pkg.Version(), pkg.Description())
case mode == SearchMode && installed == true:
case mode == SearchMode && !installed:
fmt.Printf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[32;40mInstalled\x1b[0m\n%s\n",
db.Name(), pkg.Name(), pkg.Version(), pkg.Description())
case mode == SearchMode && installed != true:
case mode == SearchMode && !installed:
fmt.Printf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s\x1b[0m\n%s\n",
db.Name(), pkg.Name(), pkg.Version(), pkg.Description())
}
@ -109,8 +109,8 @@ func SearchPackages(pkgName string, conf *alpm.PacmanConfig) (s RepoSearch, err
if err != nil {
}
dbList, err := h.SyncDbs()
localdb, err := h.LocalDb()
dbList, _ := h.SyncDbs()
localdb, _ := h.LocalDb()
var installed bool
for _, db := range dbList.Slice() {
@ -139,23 +139,24 @@ func SearchPackages(pkgName string, conf *alpm.PacmanConfig) (s RepoSearch, err
func (s *RepoSearch) PrintSearch(mode int) {
for i, pkg := range s.Results {
switch {
case mode != SearchMode && pkg.Installed == true:
case mode != SearchMode && pkg.Installed:
fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s \x1B[32;40mInstalled\033[0m\n%s\n",
i, pkg.Repository, pkg.Name, pkg.Version, pkg.Description)
case mode != SearchMode && pkg.Installed != true:
case mode != SearchMode && !pkg.Installed:
fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
i, pkg.Repository, pkg.Name, pkg.Version, pkg.Description)
case mode == SearchMode && pkg.Installed == true:
case mode == SearchMode && pkg.Installed:
fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s \x1B[32;40mInstalled\033[0m\n%s\n",
pkg.Repository, pkg.Name, pkg.Version, pkg.Description)
case mode == SearchMode && pkg.Installed != true:
case mode == SearchMode && !pkg.Installed:
fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
pkg.Repository, pkg.Name, pkg.Version, pkg.Description)
}
}
}
func passToPacman(op string, pkgs []string, flags []string) error {
// PassToPacman outsorces execution to pacman binary without modifications.
func PassToPacman(op string, pkgs []string, flags []string) error {
var cmd *exec.Cmd
var args []string