mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
add config.String() to pretty print default config in valid json
This commit is contained in:
parent
0dc94a2c31
commit
57773b6c2d
5
cmd.go
5
cmd.go
@ -273,12 +273,11 @@ func sudoLoopBackground() {
|
||||
|
||||
func sudoLoop() {
|
||||
for {
|
||||
updateSudo()
|
||||
updateSudo()
|
||||
time.Sleep(298 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func updateSudo() {
|
||||
for {
|
||||
cmd := exec.Command("sudo", "-v")
|
||||
@ -398,7 +397,7 @@ func handleVersion() {
|
||||
func handlePrint() (err error) {
|
||||
switch {
|
||||
case cmdArgs.existsArg("d", "defaultconfig"):
|
||||
fmt.Printf("%#v", config)
|
||||
fmt.Printf("%v", config)
|
||||
case cmdArgs.existsArg("n", "numberupgrades"):
|
||||
err = printNumberOfUpdates()
|
||||
case cmdArgs.existsArg("u", "upgrades"):
|
||||
|
11
config.go
11
config.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -194,3 +195,13 @@ func continueTask(s string, def string) (cont bool) {
|
||||
|
||||
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user