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
|
|
|
|
2021-08-26 21:31:43 +00:00
|
|
|
"git.rawtext.club/slope-lang/slp/args"
|
|
|
|
"git.rawtext.club/slope-lang/slp/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 {
|
2021-08-26 21:31:43 +00:00
|
|
|
fmt.Println(` < slp - slope package manager >
|
2017-08-31 09:48:00 +00:00
|
|
|
|
2021-08-26 21:31:43 +00:00
|
|
|
slp +<package> installs a package
|
|
|
|
slp -<package> removes a package
|
|
|
|
slp ^<package> updates a package
|
2017-08-31 20:23:55 +00:00
|
|
|
|
2021-08-26 21:31:43 +00:00
|
|
|
slp list lists all available packages
|
|
|
|
slp 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
|
|
|
|
|
2021-08-26 21:31:43 +00:00
|
|
|
fmt.Print(" - ")
|
2017-08-31 22:41:57 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-26 21:31:43 +00:00
|
|
|
fmt.Print(" \033[32mdone\033[0m")
|
2017-08-31 22:41:57 +00:00
|
|
|
|
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()
|
|
|
|
|
2021-08-26 21:31:43 +00:00
|
|
|
printStat("\033[1;32m", "INSTALLED", installs)
|
|
|
|
printStat("\033[1;31m", "REMOVED", removes)
|
|
|
|
printStat("\033[1;36m", "UPDATED", updates)
|
2017-08-31 19:31:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-26 21:31:43 +00:00
|
|
|
func printStat(color, prefix string, pkgs []string) {
|
2017-08-31 22:35:04 +00:00
|
|
|
count := len(pkgs)
|
|
|
|
|
2017-08-31 19:31:16 +00:00
|
|
|
if count > 0 {
|
2021-08-26 21:31:43 +00:00
|
|
|
fmt.Printf("%s%10s\033[0m", color, 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
|
|
|
}
|