2017-12-31 16:18:12 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2018-01-19 15:51:18 +01:00
|
|
|
"os"
|
|
|
|
"strings"
|
2017-12-31 16:18:12 +01:00
|
|
|
)
|
|
|
|
|
2018-01-19 15:51:18 +01:00
|
|
|
type stringSet map[string]struct{}
|
2018-01-03 20:17:57 +01:00
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (set stringSet) getAny() string {
|
|
|
|
for v := range set {
|
|
|
|
return v
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
//maybe should return error instrad
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (set stringSet) removeAny() string {
|
2018-01-04 07:01:17 +01:00
|
|
|
v := set.getAny()
|
2018-01-04 01:59:57 +01:00
|
|
|
delete(set, v)
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-04 01:59:57 +01:00
|
|
|
doubles stringSet //tracks args passed twice such as -yy and -dd
|
|
|
|
targets stringSet
|
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),
|
|
|
|
make(stringSet),
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
for k, v := range parser.targets {
|
2018-01-04 07:01:17 +01:00
|
|
|
cp.targets[k] = v
|
|
|
|
}
|
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-04 01:59:57 +01:00
|
|
|
if parser.existsArg("p", "print") {
|
2018-01-19 15:51:18 +01:00
|
|
|
return false
|
2018-01-03 19:42:40 +01:00
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-03 19:42:40 +01:00
|
|
|
switch parser.op {
|
|
|
|
case "V", "version":
|
|
|
|
return false
|
|
|
|
case "D", "database":
|
|
|
|
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":
|
|
|
|
return false
|
|
|
|
case "R", "remove":
|
|
|
|
return true
|
|
|
|
case "S", "sync":
|
2018-01-04 07:01:17 +01:00
|
|
|
if parser.existsArg("y", "refresh") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if parser.existsArg("u", "sysupgrade") {
|
|
|
|
return true
|
|
|
|
}
|
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-01-04 07:01:17 +01:00
|
|
|
if parser.existsArg("i", "info") {
|
|
|
|
return false
|
|
|
|
}
|
2018-01-03 19:42:40 +01:00
|
|
|
return true
|
|
|
|
case "T", "deptest":
|
|
|
|
return false
|
|
|
|
case "U", "upgrade":
|
|
|
|
return true
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
//yay specific
|
2018-01-03 19:42:40 +01:00
|
|
|
case "Y", "yay":
|
|
|
|
return false
|
|
|
|
case "G", "getpkgbuild":
|
|
|
|
return false
|
|
|
|
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) {
|
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
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
if parser.existsArg(option) {
|
|
|
|
parser.doubles[option] = struct{}{}
|
2018-01-04 07:01:17 +01:00
|
|
|
} else if isGlobal(option) {
|
|
|
|
parser.globals[option] = arg
|
2017-12-31 16:18:12 +01:00
|
|
|
} else {
|
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-01-04 01:59:57 +01:00
|
|
|
//multiple args acts as an OR operator
|
|
|
|
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) {
|
|
|
|
for _, option := range options {
|
|
|
|
arg, exists = parser.options[option]
|
|
|
|
|
|
|
|
if exists {
|
|
|
|
_, double = parser.doubles[option]
|
|
|
|
return
|
|
|
|
}
|
2018-01-04 07:01:17 +01:00
|
|
|
|
2018-01-04 22:21:39 +01:00
|
|
|
arg, exists = parser.globals[option]
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 22:21:39 +01:00
|
|
|
if exists {
|
|
|
|
_, double = parser.doubles[option]
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
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) addTarget(targets ...string) {
|
|
|
|
for _, target := range targets {
|
|
|
|
parser.targets[target] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (parser *arguments) delTarget(targets ...string) {
|
|
|
|
for _, target := range targets {
|
|
|
|
delete(parser.targets, target)
|
|
|
|
}
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
//multiple args acts as an OR operator
|
|
|
|
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) formatTargets() (args []string) {
|
|
|
|
for target := range parser.targets {
|
|
|
|
args = append(args, target)
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
return
|
2017-12-31 16:18:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 01:59:57 +01:00
|
|
|
func (parser *arguments) formatArgs() (args []string) {
|
2018-01-03 19:42:40 +01:00
|
|
|
op := formatArg(parser.op)
|
|
|
|
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-01-04 07:01:17 +01:00
|
|
|
formatedOption := formatArg(option)
|
|
|
|
args = append(args, formatedOption)
|
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-01-04 07:01:17 +01:00
|
|
|
args = append(args, formatedOption)
|
|
|
|
}
|
|
|
|
}
|
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 {
|
|
|
|
formatedOption := formatArg(option)
|
|
|
|
args = append(args, formatedOption)
|
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) {
|
|
|
|
args = append(args, formatedOption)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func isOp(op string) bool {
|
|
|
|
switch op {
|
|
|
|
case "V", "version":
|
|
|
|
return true
|
|
|
|
case "D", "database":
|
|
|
|
return true
|
|
|
|
case "F", "files":
|
|
|
|
return true
|
|
|
|
case "Q", "query":
|
|
|
|
return true
|
|
|
|
case "R", "remove":
|
|
|
|
return true
|
|
|
|
case "S", "sync":
|
|
|
|
return true
|
|
|
|
case "T", "deptest":
|
|
|
|
return true
|
|
|
|
case "U", "upgrade":
|
|
|
|
return true
|
2018-01-19 15:51:18 +01:00
|
|
|
|
|
|
|
//yay specific
|
2017-12-31 16:18:12 +01:00
|
|
|
case "Y", "yay":
|
|
|
|
return true
|
2018-01-03 05:55:47 +01:00
|
|
|
case "G", "getpkgbuild":
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 07:01:17 +01:00
|
|
|
func isGlobal(op string) bool {
|
|
|
|
switch op {
|
|
|
|
case "b", "dbpath":
|
|
|
|
return true
|
|
|
|
case "r", "root":
|
|
|
|
return true
|
|
|
|
case "v", "verbose":
|
|
|
|
return true
|
|
|
|
case "arch":
|
|
|
|
return true
|
|
|
|
case "cachedir":
|
|
|
|
return true
|
|
|
|
case "color":
|
|
|
|
return true
|
|
|
|
case "config":
|
|
|
|
return true
|
|
|
|
case "debug":
|
|
|
|
return true
|
|
|
|
case "gpgdir":
|
|
|
|
return true
|
|
|
|
case "hookdir":
|
|
|
|
return true
|
|
|
|
case "logfile":
|
|
|
|
return true
|
|
|
|
case "noconfirm":
|
|
|
|
return true
|
|
|
|
case "confirm":
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 05:55:47 +01:00
|
|
|
func isYayParam(arg string) bool {
|
|
|
|
switch arg {
|
|
|
|
case "afterclean":
|
|
|
|
return true
|
|
|
|
case "noafterclean":
|
|
|
|
return true
|
|
|
|
case "devel":
|
|
|
|
return true
|
|
|
|
case "nodevel":
|
|
|
|
return true
|
|
|
|
case "timeupdate":
|
|
|
|
return true
|
|
|
|
case "notimeupdate":
|
|
|
|
return true
|
|
|
|
case "topdown":
|
|
|
|
return true
|
2017-12-31 16:18:12 +01:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func hasParam(arg string) bool {
|
|
|
|
switch arg {
|
|
|
|
case "dbpath", "b":
|
|
|
|
return true
|
|
|
|
case "root", "r":
|
|
|
|
return true
|
|
|
|
case "sysroot":
|
|
|
|
return true
|
|
|
|
case "config":
|
|
|
|
return true
|
|
|
|
case "ignore":
|
|
|
|
return true
|
|
|
|
case "assume-installed":
|
|
|
|
return true
|
|
|
|
case "overwrite":
|
|
|
|
return true
|
|
|
|
case "ask":
|
|
|
|
return true
|
|
|
|
case "cachedir":
|
|
|
|
return true
|
|
|
|
case "hookdir":
|
|
|
|
return true
|
|
|
|
case "logfile":
|
|
|
|
return true
|
|
|
|
case "ignoregroup":
|
|
|
|
return true
|
|
|
|
case "arch":
|
|
|
|
return true
|
|
|
|
case "print-format":
|
|
|
|
return true
|
|
|
|
case "gpgdir":
|
|
|
|
return true
|
|
|
|
case "color":
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//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
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if hasParam(char) {
|
2018-01-19 15:51:18 +01:00
|
|
|
if k < len(arg)-2 {
|
2017-12-31 16:18:12 +01:00
|
|
|
err = parser.addParam(char, arg[k+2:])
|
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
|
|
|
//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
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if hasParam(arg) {
|
|
|
|
err = parser.addParam(arg, param)
|
|
|
|
usedNext = true
|
|
|
|
} else {
|
|
|
|
err = parser.addArg(arg)
|
|
|
|
}
|
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) parseStdin() (err error) {
|
2017-12-31 16:18:12 +01:00
|
|
|
for true {
|
|
|
|
var target string
|
|
|
|
_, err = fmt.Scan(&target)
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
err = nil
|
|
|
|
}
|
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
|
|
|
parser.addTarget(target)
|
|
|
|
}
|
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
|
|
|
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 {
|
|
|
|
err = fmt.Errorf("no operation specified (use -h for help)")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, arg := range args {
|
|
|
|
var nextArg string
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if usedNext {
|
|
|
|
usedNext = false
|
|
|
|
continue
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
|
|
|
if k+1 < len(args) {
|
|
|
|
nextArg = args[k+1]
|
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.existsArg("--") {
|
|
|
|
parser.addTarget(arg)
|
|
|
|
} else if strings.HasPrefix(arg, "--") {
|
|
|
|
usedNext, err = parser.parseLongOption(arg, nextArg)
|
|
|
|
} else if strings.HasPrefix(arg, "-") {
|
|
|
|
usedNext, err = parser.parseShortOption(arg, nextArg)
|
|
|
|
} else {
|
|
|
|
parser.addTarget(arg)
|
|
|
|
}
|
2018-01-19 15:51:18 +01:00
|
|
|
|
2017-12-31 16:18:12 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
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-01-04 22:21:39 +01:00
|
|
|
if cmdArgs.existsArg("-") {
|
2018-01-19 15:51:18 +01:00
|
|
|
err = cmdArgs.parseStdin()
|
2018-01-04 22:21:39 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|