2017-12-31 16:18:12 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-07-30 02:16:36 +02:00
|
|
|
"bufio"
|
2018-05-07 02:25:47 +02:00
|
|
|
"bytes"
|
2017-12-31 16:18:12 +01:00
|
|
|
"fmt"
|
2018-05-10 21:08:16 +02:00
|
|
|
"html"
|
2018-01-19 15:51:18 +01:00
|
|
|
"os"
|
2018-03-09 03:03:04 +01:00
|
|
|
"strconv"
|
2018-01-19 15:51:18 +01:00
|
|
|
"strings"
|
2018-07-02 13:26:51 +02:00
|
|
|
"unicode"
|
2018-08-19 06:53:32 +02:00
|
|
|
|
|
|
|
rpc "github.com/mikkeloscar/aur"
|
2017-12-31 16:18:12 +01:00
|
|
|
)
|
|
|
|
|
2018-03-04 01:12:19 +01:00
|
|
|
// A basic set implementation for strings.
|
|
|
|
// This is used a lot so it deserves its own type.
|
2018-03-03 03:45:16 +01:00
|
|
|
// Other types of sets are used throughout the code but do not have
|
|
|
|
// their own typedef.
|
|
|
|
// String sets and <type>sets should be used throughout the code when applicable,
|
2018-05-12 18:16:48 +02:00
|
|
|
// they are a lot more flexible than slices and provide easy lookup.
|
2018-01-19 15:51:18 +01:00
|
|
|
type stringSet map[string]struct{}
|
2018-01-03 20:17:57 +01:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
func (set stringSet) set(v string) {
|
|
|
|
set[v] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (set stringSet) get(v string) bool {
|
|
|
|
_, exists := set[v]
|
|
|
|
return exists
|
|
|
|
}
|
|
|
|
|
|
|
|
func (set stringSet) remove(v string) {
|
|
|
|
delete(set, v)
|
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (set stringSet) toSlice() []string {
|
|
|
|
slice := make([]string, 0, len(set))
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
for v := range set {
|
|
|
|
slice = append(slice, v)
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
return slice
|
|
|
|
}
|
|
|
|
|
2018-05-08 06:06:25 +02:00
|
|
|
func (set stringSet) copy() stringSet {
|
|
|
|
newSet := make(stringSet)
|
|
|
|
|
|
|
|
for str := range set {
|
|
|
|
newSet.set(str)
|
|
|
|
}
|
|
|
|
|
|
|
|
return newSet
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:30:44 +01:00
|
|
|
func sliceToStringSet(in []string) stringSet {
|
2018-03-09 03:03:04 +01:00
|
|
|
set := make(stringSet)
|
|
|
|
|
|
|
|
for _, v := range in {
|
|
|
|
set.set(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return set
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeStringSet(in ...string) stringSet {
|
2018-03-19 16:30:44 +01:00
|
|
|
return sliceToStringSet(in)
|
2018-03-09 03:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// Parses command line arguments in a way we can interact with programmatically but
|
|
|
|
// also in a way that can easily be passed to pacman later on.
|
2018-01-04 01:59:57 +01:00
|
|
|
type arguments struct {
|
2018-01-19 15:51:18 +01:00
|
|
|
op string
|
2017-12-31 16:18:12 +01:00
|
|
|
options map[string]string
|
2018-01-04 07:01:17 +01:00
|
|
|
globals map[string]string
|
2018-03-03 03:45:16 +01:00
|
|
|
doubles stringSet // Tracks args passed twice such as -yy and -dd
|
2018-06-02 16:01:39 +02:00
|
|
|
targets []string
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func makeArguments() *arguments {
|
2018-01-19 15:51:18 +01:00
|
|
|
return &arguments{
|
2017-12-31 16:18:12 +01:00
|
|
|
"",
|
|
|
|
make(map[string]string),
|
2018-01-04 07:01:17 +01:00
|
|
|
make(map[string]string),
|
2018-01-04 01:59:57 +01:00
|
|
|
make(stringSet),
|
2018-06-02 16:01:39 +02:00
|
|
|
make([]string, 0),
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-15 14:05:38 +02:00
|
|
|
func (parser *arguments) copyGlobal() (cp *arguments) {
|
|
|
|
cp = makeArguments()
|
|
|
|
for k, v := range parser.globals {
|
|
|
|
cp.globals[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
func (parser *arguments) copy() (cp *arguments) {
|
|
|
|
cp = makeArguments()
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
cp.op = parser.op
|
2018-01-19 15:51:18 +01:00
|
|
|
|
|
|
|
for k, v := range parser.options {
|
2018-01-04 07:01:17 +01:00
|
|
|
cp.options[k] = v
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
|
|
|
for k, v := range parser.globals {
|
2018-01-04 07:01:17 +01:00
|
|
|
cp.globals[k] = v
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-06-02 16:01:39 +02:00
|
|
|
cp.targets = make([]string, len(parser.targets))
|
|
|
|
copy(cp.targets, parser.targets)
|
2018-01-19 15:51:18 +01:00
|
|
|
|
|
|
|
for k, v := range parser.doubles {
|
2018-01-04 07:01:17 +01:00
|
|
|
cp.doubles[k] = v
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) delArg(options ...string) {
|
|
|
|
for _, option := range options {
|
|
|
|
delete(parser.options, option)
|
2018-01-04 07:01:17 +01:00
|
|
|
delete(parser.globals, option)
|
2018-01-04 01:59:57 +01:00
|
|
|
delete(parser.doubles, option)
|
|
|
|
}
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) needRoot() bool {
|
|
|
|
if parser.existsArg("h", "help") {
|
2018-01-03 19:42:40 +01:00
|
|
|
return false
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-03 19:42:40 +01:00
|
|
|
switch parser.op {
|
|
|
|
case "D", "database":
|
2018-07-21 18:36:16 +02:00
|
|
|
if parser.existsArg("k", "check") {
|
|
|
|
return false
|
|
|
|
}
|
2018-01-03 19:42:40 +01:00
|
|
|
return true
|
|
|
|
case "F", "files":
|
2018-01-04 01:59:57 +01:00
|
|
|
if parser.existsArg("y", "refresh") {
|
2018-01-03 19:42:40 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
case "Q", "query":
|
2018-07-02 14:15:57 +02:00
|
|
|
if parser.existsArg("k", "check") {
|
|
|
|
return true
|
|
|
|
}
|
2018-01-03 19:42:40 +01:00
|
|
|
return false
|
|
|
|
case "R", "remove":
|
2019-05-18 06:26:22 +02:00
|
|
|
if parser.existsArg("p", "print", "print-format") {
|
|
|
|
return false
|
|
|
|
}
|
2018-01-03 19:42:40 +01:00
|
|
|
return true
|
|
|
|
case "S", "sync":
|
2018-07-25 04:45:34 +02:00
|
|
|
if parser.existsArg("y", "refresh") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if parser.existsArg("p", "print", "print-format") {
|
|
|
|
return false
|
|
|
|
}
|
2018-01-04 01:59:57 +01:00
|
|
|
if parser.existsArg("s", "search") {
|
2018-01-03 19:42:40 +01:00
|
|
|
return false
|
|
|
|
}
|
2018-01-04 01:59:57 +01:00
|
|
|
if parser.existsArg("l", "list") {
|
2018-01-03 19:42:40 +01:00
|
|
|
return false
|
|
|
|
}
|
2018-07-21 18:36:16 +02:00
|
|
|
if parser.existsArg("g", "groups") {
|
2018-07-21 17:18:19 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if parser.existsArg("i", "info") {
|
|
|
|
return false
|
|
|
|
}
|
2018-09-14 21:18:59 +02:00
|
|
|
if parser.existsArg("c", "clean") && mode == modeAUR {
|
2018-07-24 03:49:45 +02:00
|
|
|
return false
|
|
|
|
}
|
2018-07-21 17:18:19 +02:00
|
|
|
return true
|
|
|
|
case "U", "upgrade":
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) addOP(op string) (err error) {
|
|
|
|
if parser.op != "" {
|
2017-12-31 16:18:12 +01:00
|
|
|
err = fmt.Errorf("only one operation may be used at a time")
|
|
|
|
return
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
parser.op = op
|
2017-12-31 16:18:12 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) addParam(option string, arg string) (err error) {
|
2018-07-30 05:38:06 +02:00
|
|
|
if !isArg(option) {
|
|
|
|
return fmt.Errorf("invalid option '%s'", option)
|
|
|
|
}
|
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if isOp(option) {
|
2018-01-04 01:59:57 +01:00
|
|
|
err = parser.addOP(option)
|
2017-12-31 16:18:12 +01:00
|
|
|
return
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2019-03-07 21:02:44 +01:00
|
|
|
switch {
|
|
|
|
case parser.existsArg(option):
|
2018-01-04 01:59:57 +01:00
|
|
|
parser.doubles[option] = struct{}{}
|
2019-03-07 21:02:44 +01:00
|
|
|
case isGlobal(option):
|
2018-01-04 07:01:17 +01:00
|
|
|
parser.globals[option] = arg
|
2019-03-07 21:02:44 +01:00
|
|
|
default:
|
2018-01-04 01:59:57 +01:00
|
|
|
parser.options[option] = arg
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) addArg(options ...string) (err error) {
|
|
|
|
for _, option := range options {
|
|
|
|
err = parser.addParam(option, "")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 07:01:17 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// Multiple args acts as an OR operator
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) existsArg(options ...string) bool {
|
|
|
|
for _, option := range options {
|
|
|
|
_, exists := parser.options[option]
|
|
|
|
if exists {
|
|
|
|
return true
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
_, exists = parser.globals[option]
|
|
|
|
if exists {
|
|
|
|
return true
|
|
|
|
}
|
2018-01-04 01:59:57 +01:00
|
|
|
}
|
|
|
|
return false
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 22:21:39 +01:00
|
|
|
func (parser *arguments) getArg(options ...string) (arg string, double bool, exists bool) {
|
2018-04-16 21:22:33 +02:00
|
|
|
existCount := 0
|
|
|
|
|
2018-01-04 22:21:39 +01:00
|
|
|
for _, option := range options {
|
2018-04-27 03:43:10 +02:00
|
|
|
var value string
|
|
|
|
|
|
|
|
value, exists = parser.options[option]
|
2018-01-04 22:21:39 +01:00
|
|
|
|
|
|
|
if exists {
|
2018-04-27 03:43:10 +02:00
|
|
|
arg = value
|
2018-04-16 21:22:33 +02:00
|
|
|
existCount++
|
|
|
|
_, exists = parser.doubles[option]
|
|
|
|
|
|
|
|
if exists {
|
|
|
|
existCount++
|
|
|
|
}
|
|
|
|
|
2018-01-04 22:21:39 +01:00
|
|
|
}
|
2018-01-04 07:01:17 +01:00
|
|
|
|
2018-04-27 03:43:10 +02:00
|
|
|
value, exists = parser.globals[option]
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 22:21:39 +01:00
|
|
|
if exists {
|
2018-04-27 03:43:10 +02:00
|
|
|
arg = value
|
2018-04-16 21:22:33 +02:00
|
|
|
existCount++
|
|
|
|
_, exists = parser.doubles[option]
|
|
|
|
|
|
|
|
if exists {
|
|
|
|
existCount++
|
|
|
|
}
|
|
|
|
|
2018-01-04 22:21:39 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-04-16 21:22:33 +02:00
|
|
|
double = existCount >= 2
|
2018-04-17 19:24:39 +02:00
|
|
|
exists = existCount >= 1
|
2018-04-16 21:22:33 +02:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) addTarget(targets ...string) {
|
2018-06-02 16:01:39 +02:00
|
|
|
parser.targets = append(parser.targets, targets...)
|
2018-01-04 01:59:57 +01:00
|
|
|
}
|
|
|
|
|
2018-06-02 16:01:39 +02:00
|
|
|
func (parser *arguments) clearTargets() {
|
|
|
|
parser.targets = make([]string, 0)
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// Multiple args acts as an OR operator
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) existsDouble(options ...string) bool {
|
|
|
|
for _, option := range options {
|
|
|
|
_, exists := parser.doubles[option]
|
|
|
|
if exists {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
return false
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) formatArgs() (args []string) {
|
2018-01-21 12:48:09 +01:00
|
|
|
var op string
|
|
|
|
|
|
|
|
if parser.op != "" {
|
|
|
|
op = formatArg(parser.op)
|
|
|
|
}
|
|
|
|
|
2018-01-03 19:42:40 +01:00
|
|
|
args = append(args, op)
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
for option, arg := range parser.options {
|
2018-02-20 18:03:50 +01:00
|
|
|
if option == "--" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-05-12 18:16:48 +02:00
|
|
|
formattedOption := formatArg(option)
|
|
|
|
args = append(args, formattedOption)
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
if hasParam(option) {
|
2018-01-03 19:42:40 +01:00
|
|
|
args = append(args, arg)
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if parser.existsDouble(option) {
|
2018-05-12 18:16:48 +02:00
|
|
|
args = append(args, formattedOption)
|
2018-01-04 07:01:17 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (parser *arguments) formatGlobals() (args []string) {
|
|
|
|
for option, arg := range parser.globals {
|
2018-05-12 18:16:48 +02:00
|
|
|
formattedOption := formatArg(option)
|
|
|
|
args = append(args, formattedOption)
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
if hasParam(option) {
|
|
|
|
args = append(args, arg)
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
if parser.existsDouble(option) {
|
2018-05-12 18:16:48 +02:00
|
|
|
args = append(args, formattedOption)
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
return
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func formatArg(arg string) string {
|
|
|
|
if len(arg) > 1 {
|
|
|
|
arg = "--" + arg
|
|
|
|
} else {
|
|
|
|
arg = "-" + arg
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
2018-07-30 05:38:06 +02:00
|
|
|
func isArg(arg string) bool {
|
|
|
|
switch arg {
|
2018-08-02 17:51:33 +02:00
|
|
|
case "-", "--":
|
2018-10-13 02:31:16 +02:00
|
|
|
case "ask":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "D", "database":
|
|
|
|
case "Q", "query":
|
|
|
|
case "R", "remove":
|
|
|
|
case "S", "sync":
|
|
|
|
case "T", "deptest":
|
|
|
|
case "U", "upgrade":
|
|
|
|
case "F", "files":
|
|
|
|
case "V", "version":
|
|
|
|
case "h", "help":
|
|
|
|
case "Y", "yay":
|
2018-08-02 22:58:03 +02:00
|
|
|
case "P", "show":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "G", "getpkgbuild":
|
|
|
|
case "b", "dbpath":
|
|
|
|
case "r", "root":
|
|
|
|
case "v", "verbose":
|
|
|
|
case "arch":
|
|
|
|
case "cachedir":
|
|
|
|
case "color":
|
|
|
|
case "config":
|
|
|
|
case "debug":
|
|
|
|
case "gpgdir":
|
|
|
|
case "hookdir":
|
|
|
|
case "logfile":
|
|
|
|
case "noconfirm":
|
|
|
|
case "confirm":
|
2018-10-09 16:59:17 +02:00
|
|
|
case "disable-download-timeout":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "sysroot":
|
|
|
|
case "d", "nodeps":
|
2018-09-23 23:08:45 +02:00
|
|
|
case "assume-installed":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "dbonly":
|
|
|
|
case "noprogressbar":
|
|
|
|
case "noscriptlet":
|
2018-10-09 17:13:40 +02:00
|
|
|
case "p", "print":
|
2018-10-09 16:59:17 +02:00
|
|
|
case "print-format":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "asdeps":
|
|
|
|
case "asexplicit":
|
|
|
|
case "ignore":
|
|
|
|
case "ignoregroup":
|
|
|
|
case "needed":
|
|
|
|
case "overwrite":
|
2018-08-30 16:30:52 +02:00
|
|
|
case "f", "force":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "c", "changelog":
|
|
|
|
case "deps":
|
|
|
|
case "e", "explicit":
|
|
|
|
case "g", "groups":
|
|
|
|
case "i", "info":
|
|
|
|
case "k", "check":
|
|
|
|
case "l", "list":
|
|
|
|
case "m", "foreign":
|
|
|
|
case "n", "native":
|
|
|
|
case "o", "owns":
|
|
|
|
case "file":
|
|
|
|
case "q", "quiet":
|
|
|
|
case "s", "search":
|
|
|
|
case "t", "unrequired":
|
|
|
|
case "u", "upgrades":
|
|
|
|
case "cascade":
|
|
|
|
case "nosave":
|
|
|
|
case "recursive":
|
|
|
|
case "unneeded":
|
|
|
|
case "clean":
|
|
|
|
case "sysupgrade":
|
|
|
|
case "w", "downloadonly":
|
|
|
|
case "y", "refresh":
|
|
|
|
case "x", "regex":
|
|
|
|
case "machinereadable":
|
|
|
|
//yay options
|
2018-08-19 06:05:16 +02:00
|
|
|
case "aururl":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "save":
|
2018-09-27 17:12:43 +02:00
|
|
|
case "afterclean", "cleanafter":
|
|
|
|
case "noafterclean", "nocleanafter":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "devel":
|
|
|
|
case "nodevel":
|
|
|
|
case "timeupdate":
|
|
|
|
case "notimeupdate":
|
|
|
|
case "topdown":
|
|
|
|
case "bottomup":
|
|
|
|
case "completioninterval":
|
|
|
|
case "sortby":
|
|
|
|
case "redownload":
|
|
|
|
case "redownloadall":
|
|
|
|
case "noredownload":
|
|
|
|
case "rebuild":
|
|
|
|
case "rebuildall":
|
|
|
|
case "rebuildtree":
|
|
|
|
case "norebuild":
|
2018-10-15 15:15:53 +02:00
|
|
|
case "batchinstall":
|
|
|
|
case "nobatchinstall":
|
2018-07-30 05:38:06 +02:00
|
|
|
case "answerclean":
|
|
|
|
case "noanswerclean":
|
|
|
|
case "answerdiff":
|
|
|
|
case "noanswerdiff":
|
|
|
|
case "answeredit":
|
|
|
|
case "noansweredit":
|
|
|
|
case "answerupgrade":
|
|
|
|
case "noanswerupgrade":
|
|
|
|
case "gitclone":
|
|
|
|
case "nogitclone":
|
|
|
|
case "gpgflags":
|
|
|
|
case "mflags":
|
|
|
|
case "gitflags":
|
|
|
|
case "builddir":
|
|
|
|
case "editor":
|
|
|
|
case "editorflags":
|
|
|
|
case "makepkg":
|
|
|
|
case "makepkgconf":
|
|
|
|
case "nomakepkgconf":
|
|
|
|
case "pacman":
|
|
|
|
case "tar":
|
|
|
|
case "git":
|
|
|
|
case "gpg":
|
|
|
|
case "requestsplitn":
|
|
|
|
case "sudoloop":
|
|
|
|
case "nosudoloop":
|
|
|
|
case "provides":
|
|
|
|
case "noprovides":
|
|
|
|
case "pgpfetch":
|
|
|
|
case "nopgpfetch":
|
|
|
|
case "upgrademenu":
|
|
|
|
case "noupgrademenu":
|
|
|
|
case "cleanmenu":
|
|
|
|
case "nocleanmenu":
|
|
|
|
case "diffmenu":
|
|
|
|
case "nodiffmenu":
|
|
|
|
case "editmenu":
|
|
|
|
case "noeditmenu":
|
|
|
|
case "useask":
|
|
|
|
case "nouseask":
|
|
|
|
case "combinedupgrade":
|
|
|
|
case "nocombinedupgrade":
|
|
|
|
case "a", "aur":
|
|
|
|
case "repo":
|
|
|
|
case "removemake":
|
|
|
|
case "noremovemake":
|
|
|
|
case "askremovemake":
|
2018-08-02 22:58:03 +02:00
|
|
|
case "complete":
|
|
|
|
case "stats":
|
|
|
|
case "news":
|
|
|
|
case "gendb":
|
|
|
|
case "currentconfig":
|
2018-07-30 05:38:06 +02:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2018-07-30 05:49:17 +02:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleConfig(option, value string) bool {
|
|
|
|
switch option {
|
2018-08-19 06:05:16 +02:00
|
|
|
case "aururl":
|
|
|
|
config.AURURL = value
|
2018-07-30 05:49:17 +02:00
|
|
|
case "save":
|
|
|
|
shouldSaveConfig = true
|
2018-09-27 17:12:43 +02:00
|
|
|
case "afterclean", "cleanafter":
|
2018-07-30 05:49:17 +02:00
|
|
|
config.CleanAfter = true
|
2018-09-27 17:12:43 +02:00
|
|
|
case "noafterclean", "nocleanafter":
|
2018-07-30 05:49:17 +02:00
|
|
|
config.CleanAfter = false
|
|
|
|
case "devel":
|
|
|
|
config.Devel = true
|
|
|
|
case "nodevel":
|
|
|
|
config.Devel = false
|
|
|
|
case "timeupdate":
|
|
|
|
config.TimeUpdate = true
|
|
|
|
case "notimeupdate":
|
|
|
|
config.TimeUpdate = false
|
|
|
|
case "topdown":
|
2018-09-14 21:18:59 +02:00
|
|
|
config.SortMode = topDown
|
2018-07-30 05:49:17 +02:00
|
|
|
case "bottomup":
|
2018-09-14 21:18:59 +02:00
|
|
|
config.SortMode = bottomUp
|
2018-07-30 05:49:17 +02:00
|
|
|
case "completioninterval":
|
|
|
|
n, err := strconv.Atoi(value)
|
|
|
|
if err == nil {
|
|
|
|
config.CompletionInterval = n
|
|
|
|
}
|
|
|
|
case "sortby":
|
|
|
|
config.SortBy = value
|
|
|
|
case "noconfirm":
|
|
|
|
config.NoConfirm = true
|
|
|
|
case "config":
|
|
|
|
config.PacmanConf = value
|
|
|
|
case "redownload":
|
|
|
|
config.ReDownload = "yes"
|
|
|
|
case "redownloadall":
|
|
|
|
config.ReDownload = "all"
|
|
|
|
case "noredownload":
|
|
|
|
config.ReDownload = "no"
|
|
|
|
case "rebuild":
|
|
|
|
config.ReBuild = "yes"
|
|
|
|
case "rebuildall":
|
|
|
|
config.ReBuild = "all"
|
|
|
|
case "rebuildtree":
|
|
|
|
config.ReBuild = "tree"
|
|
|
|
case "norebuild":
|
|
|
|
config.ReBuild = "no"
|
2018-10-15 15:15:53 +02:00
|
|
|
case "batchinstall":
|
|
|
|
config.BatchInstall = true
|
|
|
|
case "nobatchinstall":
|
|
|
|
config.BatchInstall = false
|
2018-07-30 05:49:17 +02:00
|
|
|
case "answerclean":
|
|
|
|
config.AnswerClean = value
|
|
|
|
case "noanswerclean":
|
|
|
|
config.AnswerClean = ""
|
|
|
|
case "answerdiff":
|
|
|
|
config.AnswerDiff = value
|
|
|
|
case "noanswerdiff":
|
|
|
|
config.AnswerDiff = ""
|
|
|
|
case "answeredit":
|
|
|
|
config.AnswerEdit = value
|
|
|
|
case "noansweredit":
|
|
|
|
config.AnswerEdit = ""
|
|
|
|
case "answerupgrade":
|
|
|
|
config.AnswerUpgrade = value
|
|
|
|
case "noanswerupgrade":
|
|
|
|
config.AnswerUpgrade = ""
|
|
|
|
case "gitclone":
|
|
|
|
config.GitClone = true
|
|
|
|
case "nogitclone":
|
|
|
|
config.GitClone = false
|
|
|
|
case "gpgflags":
|
|
|
|
config.GpgFlags = value
|
|
|
|
case "mflags":
|
|
|
|
config.MFlags = value
|
|
|
|
case "gitflags":
|
|
|
|
config.GitFlags = value
|
|
|
|
case "builddir":
|
|
|
|
config.BuildDir = value
|
|
|
|
case "editor":
|
|
|
|
config.Editor = value
|
|
|
|
case "editorflags":
|
|
|
|
config.EditorFlags = value
|
|
|
|
case "makepkg":
|
|
|
|
config.MakepkgBin = value
|
|
|
|
case "makepkgconf":
|
|
|
|
config.MakepkgConf = value
|
|
|
|
case "nomakepkgconf":
|
|
|
|
config.MakepkgConf = ""
|
|
|
|
case "pacman":
|
|
|
|
config.PacmanBin = value
|
|
|
|
case "tar":
|
|
|
|
config.TarBin = value
|
|
|
|
case "git":
|
|
|
|
config.GitBin = value
|
|
|
|
case "gpg":
|
|
|
|
config.GpgBin = value
|
|
|
|
case "requestsplitn":
|
|
|
|
n, err := strconv.Atoi(value)
|
|
|
|
if err == nil && n > 0 {
|
|
|
|
config.RequestSplitN = n
|
|
|
|
}
|
|
|
|
case "sudoloop":
|
|
|
|
config.SudoLoop = true
|
|
|
|
case "nosudoloop":
|
|
|
|
config.SudoLoop = false
|
|
|
|
case "provides":
|
|
|
|
config.Provides = true
|
|
|
|
case "noprovides":
|
|
|
|
config.Provides = false
|
|
|
|
case "pgpfetch":
|
|
|
|
config.PGPFetch = true
|
|
|
|
case "nopgpfetch":
|
|
|
|
config.PGPFetch = false
|
|
|
|
case "upgrademenu":
|
|
|
|
config.UpgradeMenu = true
|
|
|
|
case "noupgrademenu":
|
|
|
|
config.UpgradeMenu = false
|
|
|
|
case "cleanmenu":
|
|
|
|
config.CleanMenu = true
|
|
|
|
case "nocleanmenu":
|
|
|
|
config.CleanMenu = false
|
|
|
|
case "diffmenu":
|
|
|
|
config.DiffMenu = true
|
|
|
|
case "nodiffmenu":
|
|
|
|
config.DiffMenu = false
|
|
|
|
case "editmenu":
|
|
|
|
config.EditMenu = true
|
|
|
|
case "noeditmenu":
|
|
|
|
config.EditMenu = false
|
|
|
|
case "useask":
|
|
|
|
config.UseAsk = true
|
|
|
|
case "nouseask":
|
|
|
|
config.UseAsk = false
|
|
|
|
case "combinedupgrade":
|
|
|
|
config.CombinedUpgrade = true
|
|
|
|
case "nocombinedupgrade":
|
|
|
|
config.CombinedUpgrade = false
|
|
|
|
case "a", "aur":
|
2018-09-14 21:18:59 +02:00
|
|
|
mode = modeAUR
|
2018-07-30 05:49:17 +02:00
|
|
|
case "repo":
|
2018-09-14 21:18:59 +02:00
|
|
|
mode = modeRepo
|
2018-07-30 05:49:17 +02:00
|
|
|
case "removemake":
|
|
|
|
config.RemoveMake = "yes"
|
|
|
|
case "noremovemake":
|
|
|
|
config.RemoveMake = "no"
|
|
|
|
case "askremovemake":
|
|
|
|
config.RemoveMake = "ask"
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
2018-07-30 05:38:06 +02:00
|
|
|
}
|
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
func isOp(op string) bool {
|
|
|
|
switch op {
|
|
|
|
case "V", "version":
|
|
|
|
case "D", "database":
|
|
|
|
case "F", "files":
|
|
|
|
case "Q", "query":
|
|
|
|
case "R", "remove":
|
|
|
|
case "S", "sync":
|
|
|
|
case "T", "deptest":
|
|
|
|
case "U", "upgrade":
|
2018-07-30 05:49:17 +02:00
|
|
|
// yay specific
|
2017-12-31 16:18:12 +01:00
|
|
|
case "Y", "yay":
|
2018-08-02 22:58:03 +02:00
|
|
|
case "P", "show":
|
2018-01-03 05:55:47 +01:00
|
|
|
case "G", "getpkgbuild":
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2018-07-30 05:49:17 +02:00
|
|
|
|
|
|
|
return true
|
2018-01-03 05:55:47 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
func isGlobal(op string) bool {
|
|
|
|
switch op {
|
|
|
|
case "b", "dbpath":
|
|
|
|
case "r", "root":
|
|
|
|
case "v", "verbose":
|
|
|
|
case "arch":
|
|
|
|
case "cachedir":
|
|
|
|
case "color":
|
|
|
|
case "config":
|
|
|
|
case "debug":
|
|
|
|
case "gpgdir":
|
|
|
|
case "hookdir":
|
|
|
|
case "logfile":
|
|
|
|
case "noconfirm":
|
|
|
|
case "confirm":
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2018-07-30 05:49:17 +02:00
|
|
|
|
|
|
|
return true
|
2018-01-04 07:01:17 +01:00
|
|
|
}
|
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
func hasParam(arg string) bool {
|
|
|
|
switch arg {
|
|
|
|
case "dbpath", "b":
|
|
|
|
case "root", "r":
|
|
|
|
case "sysroot":
|
|
|
|
case "config":
|
|
|
|
case "ignore":
|
|
|
|
case "assume-installed":
|
|
|
|
case "overwrite":
|
|
|
|
case "ask":
|
|
|
|
case "cachedir":
|
|
|
|
case "hookdir":
|
|
|
|
case "logfile":
|
|
|
|
case "ignoregroup":
|
|
|
|
case "arch":
|
|
|
|
case "print-format":
|
|
|
|
case "gpgdir":
|
|
|
|
case "color":
|
2018-03-07 18:12:30 +01:00
|
|
|
//yay params
|
2018-08-19 06:05:16 +02:00
|
|
|
case "aururl":
|
2018-03-07 18:12:30 +01:00
|
|
|
case "mflags":
|
2018-03-17 21:40:24 +01:00
|
|
|
case "gpgflags":
|
2018-03-29 01:36:53 +02:00
|
|
|
case "gitflags":
|
2018-03-08 02:36:06 +01:00
|
|
|
case "builddir":
|
|
|
|
case "editor":
|
2018-04-09 21:50:18 +02:00
|
|
|
case "editorflags":
|
2018-03-08 02:36:06 +01:00
|
|
|
case "makepkg":
|
2018-07-18 01:53:53 +02:00
|
|
|
case "makepkgconf":
|
2018-03-08 02:36:06 +01:00
|
|
|
case "pacman":
|
|
|
|
case "tar":
|
|
|
|
case "git":
|
2018-03-17 21:40:24 +01:00
|
|
|
case "gpg":
|
2018-03-08 02:36:06 +01:00
|
|
|
case "requestsplitn":
|
2018-04-04 22:26:07 +02:00
|
|
|
case "answerclean":
|
2018-06-11 20:13:40 +02:00
|
|
|
case "answerdiff":
|
2018-04-04 22:26:07 +02:00
|
|
|
case "answeredit":
|
|
|
|
case "answerupgrade":
|
2018-07-24 15:42:43 +02:00
|
|
|
case "completioninterval":
|
2018-04-04 22:26:07 +02:00
|
|
|
case "sortby":
|
2017-12-31 16:18:12 +01:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2018-07-30 05:49:17 +02:00
|
|
|
|
|
|
|
return true
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// Parses short hand options such as:
|
|
|
|
// -Syu -b/some/path -
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) parseShortOption(arg string, param string) (usedNext bool, err error) {
|
2017-12-31 16:18:12 +01:00
|
|
|
if arg == "-" {
|
|
|
|
err = parser.addArg("-")
|
|
|
|
return
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
arg = arg[1:]
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
for k, _char := range arg {
|
|
|
|
char := string(_char)
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-08-02 15:43:54 +02:00
|
|
|
if hasParam(char) {
|
|
|
|
if k < len(arg)-1 {
|
|
|
|
err = parser.addParam(char, arg[k+1:])
|
2017-12-31 16:18:12 +01:00
|
|
|
} else {
|
|
|
|
usedNext = true
|
|
|
|
err = parser.addParam(char, param)
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
break
|
|
|
|
} else {
|
|
|
|
err = parser.addArg(char)
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// Parses full length options such as:
|
|
|
|
// --sync --refresh --sysupgrade --dbpath /some/path --
|
2018-01-19 15:51:18 +01:00
|
|
|
func (parser *arguments) parseLongOption(arg string, param string) (usedNext bool, err error) {
|
2017-12-31 16:18:12 +01:00
|
|
|
if arg == "--" {
|
|
|
|
err = parser.addArg(arg)
|
|
|
|
return
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
arg = arg[2:]
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2019-03-07 21:02:44 +01:00
|
|
|
switch split := strings.SplitN(arg, "=", 2); {
|
|
|
|
case len(split) == 2:
|
2018-08-08 17:03:39 +02:00
|
|
|
err = parser.addParam(split[0], split[1])
|
2019-03-07 21:02:44 +01:00
|
|
|
case hasParam(arg):
|
2017-12-31 16:18:12 +01:00
|
|
|
err = parser.addParam(arg, param)
|
|
|
|
usedNext = true
|
2019-03-07 21:02:44 +01:00
|
|
|
default:
|
2017-12-31 16:18:12 +01:00
|
|
|
err = parser.addArg(arg)
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-30 02:16:36 +02:00
|
|
|
func (parser *arguments) parseStdin() error {
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
scanner.Split(bufio.ScanLines)
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-07-30 02:16:36 +02:00
|
|
|
for scanner.Scan() {
|
|
|
|
parser.addTarget(scanner.Text())
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
2018-07-30 02:16:36 +02:00
|
|
|
|
|
|
|
return os.Stdin.Close()
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 15:51:18 +01:00
|
|
|
func (parser *arguments) parseCommandLine() (err error) {
|
2017-12-31 16:18:12 +01:00
|
|
|
args := os.Args[1:]
|
|
|
|
usedNext := false
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if len(args) < 1 {
|
2018-03-31 22:55:15 +02:00
|
|
|
parser.parseShortOption("-Syu", "")
|
|
|
|
} else {
|
|
|
|
for k, arg := range args {
|
|
|
|
var nextArg string
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-03-31 22:55:15 +02:00
|
|
|
if usedNext {
|
|
|
|
usedNext = false
|
|
|
|
continue
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-03-31 22:55:15 +02:00
|
|
|
if k+1 < len(args) {
|
|
|
|
nextArg = args[k+1]
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2019-03-07 21:02:44 +01:00
|
|
|
switch {
|
|
|
|
case parser.existsArg("--"):
|
2018-03-31 22:55:15 +02:00
|
|
|
parser.addTarget(arg)
|
2019-03-07 21:02:44 +01:00
|
|
|
case strings.HasPrefix(arg, "--"):
|
2018-03-31 22:55:15 +02:00
|
|
|
usedNext, err = parser.parseLongOption(arg, nextArg)
|
2019-03-07 21:02:44 +01:00
|
|
|
case strings.HasPrefix(arg, "-"):
|
2018-03-31 22:55:15 +02:00
|
|
|
usedNext, err = parser.parseShortOption(arg, nextArg)
|
2019-03-07 21:02:44 +01:00
|
|
|
default:
|
2018-03-31 22:55:15 +02:00
|
|
|
parser.addTarget(arg)
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-03-31 22:55:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if parser.op == "" {
|
|
|
|
parser.op = "Y"
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-07-28 20:51:19 +02:00
|
|
|
if parser.existsArg("-") {
|
2018-03-12 01:04:50 +01:00
|
|
|
var file *os.File
|
2018-07-28 20:51:19 +02:00
|
|
|
err = parser.parseStdin()
|
|
|
|
parser.delArg("-")
|
2018-01-04 22:21:39 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2018-03-12 01:04:50 +01:00
|
|
|
|
|
|
|
file, err = os.Open("/dev/tty")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Stdin = file
|
2018-01-04 22:21:39 +01:00
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-08-12 03:40:43 +02:00
|
|
|
cmdArgs.extractYayOptions()
|
2017-12-31 16:18:12 +01:00
|
|
|
return
|
2018-01-19 15:51:18 +01:00
|
|
|
}
|
2018-03-09 03:03:04 +01:00
|
|
|
|
2018-07-28 20:51:19 +02:00
|
|
|
func (parser *arguments) extractYayOptions() {
|
|
|
|
for option, value := range parser.options {
|
|
|
|
if handleConfig(option, value) {
|
|
|
|
parser.delArg(option)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for option, value := range parser.globals {
|
|
|
|
if handleConfig(option, value) {
|
|
|
|
parser.delArg(option)
|
|
|
|
}
|
|
|
|
}
|
2018-08-19 06:53:32 +02:00
|
|
|
|
|
|
|
rpc.AURURL = strings.TrimRight(config.AURURL, "/") + "/rpc.php?"
|
|
|
|
config.AURURL = strings.TrimRight(config.AURURL, "/")
|
2018-07-28 20:51:19 +02:00
|
|
|
}
|
|
|
|
|
2018-10-02 22:30:18 +02:00
|
|
|
//parses input for number menus split by spaces or commas
|
2018-03-09 03:03:04 +01:00
|
|
|
//supports individual selection: 1 2 3 4
|
|
|
|
//supports range selections: 1-4 10-20
|
|
|
|
//supports negation: ^1 ^1-4
|
|
|
|
//
|
|
|
|
//include and excule holds numbers that should be added and should not be added
|
2018-04-17 19:01:34 +02:00
|
|
|
//respectively. other holds anything that can't be parsed as an int. This is
|
2018-03-09 03:03:04 +01:00
|
|
|
//intended to allow words inside of number menus. e.g. 'all' 'none' 'abort'
|
|
|
|
//of course the implementation is up to the caller, this function mearley parses
|
|
|
|
//the input and organizes it
|
|
|
|
func parseNumberMenu(input string) (intRanges, intRanges, stringSet, stringSet) {
|
2018-04-27 02:25:40 +02:00
|
|
|
include := make(intRanges, 0)
|
|
|
|
exclude := make(intRanges, 0)
|
2018-03-09 03:03:04 +01:00
|
|
|
otherInclude := make(stringSet)
|
|
|
|
otherExclude := make(stringSet)
|
|
|
|
|
2018-07-02 13:26:51 +02:00
|
|
|
words := strings.FieldsFunc(input, func(c rune) bool {
|
|
|
|
return unicode.IsSpace(c) || c == ','
|
|
|
|
})
|
2018-03-09 03:03:04 +01:00
|
|
|
|
|
|
|
for _, word := range words {
|
|
|
|
var num1 int
|
|
|
|
var num2 int
|
|
|
|
var err error
|
|
|
|
invert := false
|
|
|
|
other := otherInclude
|
|
|
|
|
|
|
|
if word[0] == '^' {
|
|
|
|
invert = true
|
|
|
|
other = otherExclude
|
|
|
|
word = word[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
ranges := strings.SplitN(word, "-", 2)
|
|
|
|
|
|
|
|
num1, err = strconv.Atoi(ranges[0])
|
|
|
|
if err != nil {
|
|
|
|
other.set(strings.ToLower(word))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(ranges) == 2 {
|
|
|
|
num2, err = strconv.Atoi(ranges[1])
|
|
|
|
if err != nil {
|
|
|
|
other.set(strings.ToLower(word))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
num2 = num1
|
|
|
|
}
|
|
|
|
|
|
|
|
mi := min(num1, num2)
|
|
|
|
ma := max(num1, num2)
|
|
|
|
|
|
|
|
if !invert {
|
|
|
|
include = append(include, makeIntRange(mi, ma))
|
|
|
|
} else {
|
|
|
|
exclude = append(exclude, makeIntRange(mi, ma))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return include, exclude, otherInclude, otherExclude
|
|
|
|
}
|
2018-05-07 02:25:47 +02:00
|
|
|
|
|
|
|
// Crude html parsing, good enough for the arch news
|
|
|
|
// This is only displayed in the terminal so there should be no security
|
|
|
|
// concerns
|
|
|
|
func parseNews(str string) string {
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
var tagBuffer bytes.Buffer
|
|
|
|
var escapeBuffer bytes.Buffer
|
|
|
|
inTag := false
|
|
|
|
inEscape := false
|
|
|
|
|
|
|
|
for _, char := range str {
|
|
|
|
if inTag {
|
|
|
|
if char == '>' {
|
|
|
|
inTag = false
|
|
|
|
switch tagBuffer.String() {
|
|
|
|
case "code":
|
|
|
|
buffer.WriteString(cyanCode)
|
|
|
|
case "/code":
|
|
|
|
buffer.WriteString(resetCode)
|
|
|
|
case "/p":
|
|
|
|
buffer.WriteRune('\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
tagBuffer.WriteRune(char)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if inEscape {
|
|
|
|
if char == ';' {
|
|
|
|
inEscape = false
|
2018-05-07 07:26:29 +02:00
|
|
|
escapeBuffer.WriteRune(char)
|
|
|
|
s := html.UnescapeString(escapeBuffer.String())
|
|
|
|
buffer.WriteString(s)
|
2018-05-07 02:25:47 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
escapeBuffer.WriteRune(char)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if char == '<' {
|
|
|
|
inTag = true
|
|
|
|
tagBuffer.Reset()
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if char == '&' {
|
|
|
|
inEscape = true
|
|
|
|
escapeBuffer.Reset()
|
2018-05-07 07:26:29 +02:00
|
|
|
escapeBuffer.WriteRune(char)
|
2018-05-07 02:25:47 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.WriteRune(char)
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.WriteString(resetCode)
|
|
|
|
return buffer.String()
|
|
|
|
}
|