Rework some of the yay specific operations

Some of the yay specific operations such as:
	'-Qstats' '-Cd'
Break the standard pacamn has set.

Most yay specific specific options have been moved into their own
operator:
	'-Y' '--yay'
	'-Qstats' -> '-Y --stats'
	'--Cd' -> '-Y --cleandeps'
	'--gendb' -> '-Y --gendb'
Although:
	'-G'
has been kepts and and alias has been added for is:
	'--getpkgbuild'

This shouldnt feel too different for most people given that yay will
default to:
	'-Y'
when no operator has been specified. So calls like:
	'yay --gendb'
will still work as they did.

Internally handleConfig has been partially refactored. Now all that
remians in setters for config. All flags that did anything beond setting
config have been moved to handleYay(). This means less nasty
os.Exit()'s and nicer flow control.

The usage has also been updated. The options changes have been added but
the layout has also been tweaked a bit.

Lastly on the things not done:
	Man page has not been updated
	Shell completion has not been updated

This will be done in further commits as the usage is not guaranteed
to stay the same between now the completion of the argument system.
This commit is contained in:
morganamilo committed 2018-01-04 08:32:44 +00:00
1 parent 19efb1f121
commit 765b767333
2 files changed
+121 -58

No files matched your search

+96 -58
View File
@@ -13,38 +13,43 @@ import (
)
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)>
fmt.Println(`Usage:
yay <operation> [...]
yay <package(s)>
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
yay -Cd remove unneeded dependencies
yay -G [package(s)] get pkgbuild from ABS or AUR
yay --gendb generates development package DB used for updating.
New operations:
yay {-Y --yay} [options] [package(s)]
yay {-G --getpkgbuild} [package(s)]
Permanent configuration options:
--topdown shows repository's packages first and then aur's
--bottomup shows aur's packages first and then repository's
--devel Check -git/-svn/-hg development version
--nodevel Disable development version checking
--afterclean Clean package sources after successful build
--noafterclean Disable package sources cleaning after successful build
--timeupdate Check package's modification date and version
--notimeupdate Check only package version change
Permanent configuration options:
--topdown Shows repository's packages first and then aur's
--bottomup Shows aur's packages first and then repository's
--devel Check -git/-svn/-hg development version
--nodevel Disable development version checking
--afterclean Clean package sources after successful build
--noafterclean Disable package sources cleaning after successful build
--timeupdate Check package's modification date and version
--notimeupdate Check only package version change
New options:
--noconfirm skip user input on package install
--printconfig Prints current yay configuration
`)
Yay specific options:
--printconfig Prints current yay configuration
--stats Displays system information
--cleandeps Remove unneeded dependencies
--gendb Generates development package DB used for updating.
If no operation is provided -Y will be assumed
`)
}
func init() {
@@ -221,7 +226,7 @@ func handleCmd(parser *argParser) (changedConfig bool, err error) {
case "U", "upgrade":
//passToPacman()
case "Y", "--yay":
err = handleYogurt(parser)
err = handleYay(parser)
default:
//this means we allowed an op but not implement it
//if this happens it an error in the code and not the usage
@@ -243,19 +248,19 @@ func handleConfig(option string) (changedConfig bool, err error) {
config.CleanAfter = true
case "noafterclean":
config.CleanAfter = false
case "printconfig":
fmt.Printf("%#v", config)
os.Exit(0)
case "gendb":
err = createDevelDB()
if err != nil {
fmt.Println(err)
}
err = saveVCSInfo()
if err != nil {
fmt.Println(err)
}
os.Exit(0)
// case "printconfig":
// fmt.Printf("%#v", config)
// os.Exit(0)
// case "gendb":
// err = createDevelDB()
// if err != nil {
// fmt.Println(err)
// }
// err = saveVCSInfo()
// if err != nil {
// fmt.Println(err)
// }
// os.Exit(0)
case "devel":
config.Devel = true
case "nodevel":
@@ -266,20 +271,20 @@ func handleConfig(option string) (changedConfig bool, err error) {
config.TimeUpdate = false
case "topdown":
config.SortMode = TopDown
case "complete":
config.Shell = "sh"
complete()
os.Exit(0)
case "fcomplete":
config.Shell = fishShell
complete()
os.Exit(0)
case "help":
usage()
os.Exit(0)
case "version":
fmt.Printf("yay v%s\n", version)
os.Exit(0)
// case "complete":
// config.Shell = "sh"
// complete()
// os.Exit(0)
// case "fcomplete":
// config.Shell = fishShell
// complete()
// os.Exit(0)
// case "help":
// usage()
// os.Exit(0)
// case "version":
// fmt.Printf("yay v%s\n", version)
// os.Exit(0)
case "noconfirm":
config.NoConfirm = true
default:
@@ -291,7 +296,40 @@ func handleConfig(option string) (changedConfig bool, err error) {
}
func handleVersion() {
usage()
fmt.Printf("yay v%s\n", version)
}
func handleYay(parser *argParser) (err error) {
//_, options, targets := parser.formatArgs()
if parser.existsArg("h") || parser.existsArg("help") {
usage()
} else if parser.existsArg("printconfig") {
fmt.Printf("%#v", config)
} else if parser.existsArg("gendb") {
err = createDevelDB()
if err != nil {
return
}
err = saveVCSInfo()
if err != nil {
return
}
} else if parser.existsArg("complete") {
config.Shell = "sh"
complete()
} else if parser.existsArg("fcomplete") {
config.Shell = "fish"
complete()
} else if parser.existsArg("stats") {
err = localStatistics()
} else if parser.existsArg("cleandeps") {
_,_,targets := parser.formatArgs()
err = cleanDependencies(targets)
} else {
err = handleYogurt(parser)
}
return
}
func handleYogurt(parser *argParser) (err error) {
+25
View File
@@ -134,8 +134,33 @@ func isOp(op string) bool {
return true
case "U", "upgrade":
return true
//yay specific
case "Y", "yay":
return true
case "G", "getpkgbuild":
return true
default:
return false
}
}
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
default:
return false
}