mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Merge pull request #168 from seankhliao/master
add config.String() to pretty print default config in valid json
This commit is contained in:
commit
f000afaa42
3 changed files with 24 additions and 4 deletions
10
cmd.go
10
cmd.go
|
@ -48,7 +48,8 @@ Permanent configuration options:
|
|||
|
||||
Print specific options:
|
||||
-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
|
||||
-s --stats Display system package statistics
|
||||
-u --upgrades Print update list
|
||||
|
@ -278,7 +279,6 @@ func sudoLoop() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func updateSudo() {
|
||||
for {
|
||||
cmd := exec.Command("sudo", "-v")
|
||||
|
@ -398,7 +398,11 @@ func handleVersion() {
|
|||
func handlePrint() (err error) {
|
||||
switch {
|
||||
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"):
|
||||
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()
|
||||
}
|
||||
|
|
5
yay.8
5
yay.8
|
@ -63,6 +63,11 @@ Remove unneeded dependencies\&.
|
|||
.SH "PRINT OPTIONS (APPLY TO -P AND --PRINT)"
|
||||
\fB\-d \-\-defaultconfig\fR
|
||||
.RS 4
|
||||
Print default yay configuration\&.
|
||||
.RE
|
||||
.PP
|
||||
\fB\-g \-\-config\fR
|
||||
.RS 4
|
||||
Print current yay configuration\&.
|
||||
.RE
|
||||
.PP
|
||||
|
|
Loading…
Reference in a new issue