Merge pull request #168 from seankhliao/master

add config.String() to pretty print default config in valid json
This commit is contained in:
J Guerreiro 2018-02-27 01:44:45 +00:00 committed by GitHub
commit f000afaa42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

12
cmd.go
View file

@ -48,7 +48,8 @@ Permanent configuration options:
Print specific options: Print specific options:
-c --complete Used for completions -c --complete Used for completions
-d --defaultconfig Print current yay configuration -d --defaultconfig Print default yay configuration
-g --config Print current yay configuration
-n --numberupgrades Print number of updates -n --numberupgrades Print number of updates
-s --stats Display system package statistics -s --stats Display system package statistics
-u --upgrades Print update list -u --upgrades Print update list
@ -273,12 +274,11 @@ func sudoLoopBackground() {
func sudoLoop() { func sudoLoop() {
for { for {
updateSudo() updateSudo()
time.Sleep(298 * time.Second) time.Sleep(298 * time.Second)
} }
} }
func updateSudo() { func updateSudo() {
for { for {
cmd := exec.Command("sudo", "-v") cmd := exec.Command("sudo", "-v")
@ -398,7 +398,11 @@ func handleVersion() {
func handlePrint() (err error) { func handlePrint() (err error) {
switch { switch {
case cmdArgs.existsArg("d", "defaultconfig"): case cmdArgs.existsArg("d", "defaultconfig"):
fmt.Printf("%#v", config) var tmpConfig Configuration
defaultSettings(&tmpConfig)
fmt.Printf("%v", tmpConfig)
case cmdArgs.existsArg("g", "config"):
fmt.Printf("%v", config)
case cmdArgs.existsArg("n", "numberupgrades"): case cmdArgs.existsArg("n", "numberupgrades"):
err = printNumberOfUpdates() err = printNumberOfUpdates()
case cmdArgs.existsArg("u", "upgrades"): case cmdArgs.existsArg("u", "upgrades"):

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
@ -194,3 +195,13 @@ func continueTask(s string, def string) (cont bool) {
return true return true
} }
func (config Configuration) String() string {
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetIndent("", "\t")
if err := enc.Encode(config); err != nil {
fmt.Println(err)
}
return buf.String()
}

5
yay.8
View file

@ -63,6 +63,11 @@ Remove unneeded dependencies\&.
.SH "PRINT OPTIONS (APPLY TO -P AND --PRINT)" .SH "PRINT OPTIONS (APPLY TO -P AND --PRINT)"
\fB\-d \-\-defaultconfig\fR \fB\-d \-\-defaultconfig\fR
.RS 4 .RS 4
Print default yay configuration\&.
.RE
.PP
\fB\-g \-\-config\fR
.RS 4
Print current yay configuration\&. Print current yay configuration\&.
.RE .RE
.PP .PP