2017-08-31 00:50:03 +00:00
|
|
|
package main
|
|
|
|
|
2017-08-31 09:48:00 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2017-08-31 22:35:04 +00:00
|
|
|
"strings"
|
2017-08-31 09:48:00 +00:00
|
|
|
|
2017-08-31 19:31:16 +00:00
|
|
|
"github.com/fatih/color"
|
|
|
|
|
2017-08-31 09:48:00 +00:00
|
|
|
"github.com/Zac-Garby/plp/args"
|
2017-08-31 10:55:23 +00:00
|
|
|
"github.com/Zac-Garby/plp/operators"
|
2017-08-31 09:48:00 +00:00
|
|
|
)
|
2017-08-31 00:50:03 +00:00
|
|
|
|
|
|
|
func main() {
|
2017-08-31 09:48:00 +00:00
|
|
|
arg := os.Args
|
|
|
|
if len(arg) <= 1 {
|
2017-08-31 11:12:41 +00:00
|
|
|
fmt.Println(` < plp - Pluto Package Manager >
|
2017-08-31 09:48:00 +00:00
|
|
|
|
2017-08-31 20:23:55 +00:00
|
|
|
plp +<package> installs a package
|
|
|
|
plp -<package> removes a package
|
|
|
|
plp ^<package> updates a package
|
|
|
|
|
|
|
|
plp list lists all available packages
|
|
|
|
plp gen creates a new package
|
2017-08-31 11:12:41 +00:00
|
|
|
`)
|
2017-08-31 09:48:00 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-31 12:00:45 +00:00
|
|
|
if arg[1] == "list" {
|
|
|
|
err := operators.List()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-31 20:23:55 +00:00
|
|
|
if arg[1] == "gen" {
|
|
|
|
err := operators.Generate()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-31 19:31:16 +00:00
|
|
|
ops, err := args.Parse(arg[1:])
|
2017-08-31 00:50:03 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-31 10:58:21 +00:00
|
|
|
var (
|
2017-08-31 22:35:04 +00:00
|
|
|
installs []string
|
|
|
|
removes []string
|
|
|
|
updates []string
|
2017-08-31 10:58:21 +00:00
|
|
|
)
|
|
|
|
|
2017-08-31 10:55:23 +00:00
|
|
|
for _, op := range ops {
|
|
|
|
var err error
|
|
|
|
|
2017-08-31 22:41:57 +00:00
|
|
|
fmt.Printf(" - ")
|
|
|
|
|
2017-08-31 10:55:23 +00:00
|
|
|
switch op.Type {
|
|
|
|
case args.INSTALL:
|
2017-08-31 22:41:57 +00:00
|
|
|
fmt.Printf("installing %s", op.Package)
|
2017-08-31 10:55:23 +00:00
|
|
|
err = operators.Install(op.Package)
|
2017-08-31 22:35:04 +00:00
|
|
|
installs = append(installs, op.Package)
|
2017-08-31 10:55:23 +00:00
|
|
|
case args.REMOVE:
|
2017-08-31 22:41:57 +00:00
|
|
|
fmt.Printf("removing %s", op.Package)
|
2017-08-31 10:55:23 +00:00
|
|
|
err = operators.Remove(op.Package)
|
2017-08-31 22:35:04 +00:00
|
|
|
removes = append(removes, op.Package)
|
2017-08-31 11:00:27 +00:00
|
|
|
case args.UPDATE:
|
2017-08-31 22:41:57 +00:00
|
|
|
fmt.Printf("updating %s", op.Package)
|
2017-08-31 11:00:27 +00:00
|
|
|
err = operators.Update(op.Package)
|
2017-08-31 22:35:04 +00:00
|
|
|
updates = append(updates, op.Package)
|
2017-08-31 10:55:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 22:41:57 +00:00
|
|
|
fmt.Print(" ")
|
|
|
|
color.Green("done")
|
|
|
|
|
2017-08-31 10:55:23 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
2017-08-31 10:58:21 +00:00
|
|
|
|
2017-08-31 19:31:16 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
var (
|
|
|
|
green = color.New(color.FgGreen, color.Bold)
|
|
|
|
cyan = color.New(color.FgCyan, color.Bold)
|
|
|
|
red = color.New(color.FgRed, color.Bold)
|
|
|
|
)
|
|
|
|
|
|
|
|
printStat(green, "INSTALLED", installs)
|
|
|
|
printStat(red, "REMOVED", removes)
|
|
|
|
printStat(cyan, "UPDATED", updates)
|
|
|
|
}
|
|
|
|
|
2017-08-31 22:35:04 +00:00
|
|
|
func printStat(colour *color.Color, prefix string, pkgs []string) {
|
|
|
|
count := len(pkgs)
|
|
|
|
|
2017-08-31 19:31:16 +00:00
|
|
|
if count > 0 {
|
2017-08-31 19:31:45 +00:00
|
|
|
colour.Printf("%10s ", prefix)
|
2017-08-31 19:31:16 +00:00
|
|
|
|
|
|
|
if count > 1 {
|
|
|
|
fmt.Printf("%d packages", count)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("1 package")
|
|
|
|
}
|
|
|
|
|
2017-08-31 22:35:04 +00:00
|
|
|
fmt.Printf(" (%s)\n", strings.Join(pkgs, ", "))
|
2017-08-31 19:31:16 +00:00
|
|
|
}
|
2017-08-31 00:50:03 +00:00
|
|
|
}
|