From 57773b6c2d1fcf78e94820ea47916ebecc4ce5a4 Mon Sep 17 00:00:00 2001 From: Sean Liao Date: Tue, 20 Feb 2018 22:24:48 +0800 Subject: [PATCH 1/4] add config.String() to pretty print default config in valid json --- cmd.go | 5 ++--- config.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd.go b/cmd.go index 7642a772..23f1e9d8 100644 --- a/cmd.go +++ b/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"): diff --git a/config.go b/config.go index 409c51bb..65eb221e 100644 --- a/config.go +++ b/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() +} From d12685debc7c5cb96141de570ee6c6386e056558 Mon Sep 17 00:00:00 2001 From: Sean Liao Date: Tue, 20 Feb 2018 23:08:29 +0800 Subject: [PATCH 2/4] separate printing default and current config --- cmd.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd.go b/cmd.go index 23f1e9d8..0ea0a993 100644 --- a/cmd.go +++ b/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 @@ -397,6 +398,10 @@ func handleVersion() { func handlePrint() (err error) { switch { case cmdArgs.existsArg("d", "defaultconfig"): + 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() From 56db82ed10ec2acfc3ae70d85dad119f2e7242ca Mon Sep 17 00:00:00 2001 From: Sean Liao Date: Tue, 20 Feb 2018 23:12:07 +0800 Subject: [PATCH 3/4] fix stray tab --- cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd.go b/cmd.go index 0ea0a993..075c427e 100644 --- a/cmd.go +++ b/cmd.go @@ -49,7 +49,7 @@ Permanent configuration options: Print specific options: -c --complete Used for completions -d --defaultconfig Print default yay configuration - -g --config Print current 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 From 3355604910a75d83bbdf3f77ec85112195ea7613 Mon Sep 17 00:00:00 2001 From: Sean Liao Date: Tue, 20 Feb 2018 23:30:56 +0800 Subject: [PATCH 4/4] update manpage for print configs --- yay.8 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yay.8 b/yay.8 index d0a1e048..6bdd4e50 100644 --- a/yay.8 +++ b/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