simple printing
This commit is contained in:
parent
5b7b4b8a71
commit
8d82534461
2 changed files with 9 additions and 27 deletions
|
|
@ -46,9 +46,6 @@ func listRun(opts *ListOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cs := opts.IO.ColorScheme()
|
||||
isTTY := opts.IO.IsStdoutTTY()
|
||||
|
||||
var host string
|
||||
if opts.Hostname != "" {
|
||||
host = opts.Hostname
|
||||
|
|
@ -59,23 +56,14 @@ func listRun(opts *ListOptions) error {
|
|||
}
|
||||
}
|
||||
|
||||
if isTTY {
|
||||
fmt.Fprint(opts.IO.Out, cs.Grayf("Settings configured for %s\n\n", host))
|
||||
}
|
||||
|
||||
configOptions := config.ConfigOptions()
|
||||
|
||||
for _, key := range configOptions {
|
||||
val, err := cfg.Get(opts.Hostname, key.Key)
|
||||
val, err := cfg.Get(host, key.Key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
configLine := fmt.Sprintf("%s: %s", key.Key, val)
|
||||
if isTTY && key.DefaultValue != "" && val != key.DefaultValue {
|
||||
configLine = cs.Bold(configLine)
|
||||
configLine += fmt.Sprintf(" (default: %s)", key.DefaultValue)
|
||||
}
|
||||
fmt.Fprint(opts.IO.Out, configLine, "\n")
|
||||
fmt.Fprint(opts.IO.Out, fmt.Sprintf("%s=%s\n", key.Key, val))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -72,13 +72,11 @@ func Test_listRun(t *testing.T) {
|
|||
name string
|
||||
input *ListOptions
|
||||
config config.ConfigStub
|
||||
isTTY bool
|
||||
stdout string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "list",
|
||||
isTTY: true,
|
||||
name: "list",
|
||||
config: config.ConfigStub{
|
||||
"HOST:git_protocol": "ssh",
|
||||
"HOST:editor": "/usr/bin/vim",
|
||||
|
|
@ -88,22 +86,18 @@ func Test_listRun(t *testing.T) {
|
|||
"HOST:browser": "brave",
|
||||
},
|
||||
input: &ListOptions{Hostname: "HOST"}, // ConfigStub gives empty DefaultHost
|
||||
stdout: `Settings configured for HOST
|
||||
|
||||
git_protocol: ssh (default: https)
|
||||
editor: /usr/bin/vim
|
||||
prompt: disabled (default: enabled)
|
||||
pager: less
|
||||
http_unix_socket:
|
||||
browser: brave
|
||||
stdout: `git_protocol=ssh
|
||||
editor=/usr/bin/vim
|
||||
prompt=disabled
|
||||
pager=less
|
||||
http_unix_socket=
|
||||
browser=brave
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
io, _, stdout, _ := iostreams.Test()
|
||||
io.SetStdoutTTY(tt.isTTY)
|
||||
io.SetStdinTTY(tt.isTTY)
|
||||
tt.input.IO = io
|
||||
tt.input.Config = func() (config.Config, error) {
|
||||
return tt.config, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue