mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 09:54:18 +02:00
add support for json color output in repl using jq, if installed (#16)
This commit is contained in:
@@ -31,7 +31,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Version string = `v0.0.9`
|
||||
Version string = `v0.0.10`
|
||||
)
|
||||
|
||||
type Cluster struct {
|
||||
@@ -55,6 +55,7 @@ type Config struct {
|
||||
All, Verbose bool // cluster status: -a -v
|
||||
Persistent, Transient, Default bool // -p -t -D cluster settings set
|
||||
Force bool // ccr follower renew: -f
|
||||
HaveJQ bool // determined at runtime by ourselfes
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
@@ -110,6 +111,8 @@ func (conf *Config) Init() error {
|
||||
}
|
||||
}
|
||||
|
||||
conf.HaveJQ = isJQinstalled()
|
||||
|
||||
conf.PrintDebug()
|
||||
|
||||
return nil
|
||||
|
||||
38
pkg/cfg/jq.go
Normal file
38
pkg/cfg/jq.go
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright © 2026 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isJQinstalled() bool {
|
||||
cmd := exec.CommandContext(context.Background(), "jq", "-h")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if strings.Contains(string(out), "Usage") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user