X Tutup
Skip to content

Commit 2843d32

Browse files
committed
init
1 parent dae77fd commit 2843d32

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

pkg/cmd/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/cli/cli/v2/internal/config"
88
cmdGet "github.com/cli/cli/v2/pkg/cmd/config/get"
9+
cmdList "github.com/cli/cli/v2/pkg/cmd/config/list"
910
cmdSet "github.com/cli/cli/v2/pkg/cmd/config/set"
1011
"github.com/cli/cli/v2/pkg/cmdutil"
1112
"github.com/spf13/cobra"
@@ -33,6 +34,7 @@ func NewCmdConfig(f *cmdutil.Factory) *cobra.Command {
3334

3435
cmd.AddCommand(cmdGet.NewCmdConfigGet(f, nil))
3536
cmd.AddCommand(cmdSet.NewCmdConfigSet(f, nil))
37+
cmd.AddCommand(cmdList.NewCmdConfigList(f, nil))
3638

3739
return cmd
3840
}

pkg/cmd/config/list/list.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package list
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/cli/cli/v2/internal/config"
7+
"github.com/cli/cli/v2/pkg/cmdutil"
8+
"github.com/cli/cli/v2/pkg/iostreams"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
type ListOptions struct {
13+
IO *iostreams.IOStreams
14+
Config func() (config.Config, error)
15+
16+
Hostname string
17+
}
18+
19+
func NewCmdConfigList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
20+
opts := &ListOptions{
21+
IO: f.IOStreams,
22+
}
23+
24+
cmd := &cobra.Command{
25+
Use: "list",
26+
Short: "Print a list of configuration keys and values",
27+
Args: cobra.ExactArgs(0),
28+
RunE: func(cmd *cobra.Command, args []string) error {
29+
opts.Config = f.Config
30+
31+
if runF != nil {
32+
return runF(opts)
33+
}
34+
35+
return listRun(opts)
36+
},
37+
}
38+
39+
cmd.Flags().StringVarP(&opts.Hostname, "host", "h", "", "Get per-host setting")
40+
41+
return cmd
42+
}
43+
44+
func listRun(opts *ListOptions) error {
45+
cfg, err := opts.Config()
46+
if err != nil {
47+
return err
48+
}
49+
50+
//cs := opts.IO.ColorScheme()
51+
isTTY := opts.IO.IsStdoutTTY()
52+
53+
host, err := cfg.DefaultHost()
54+
if err != nil {
55+
return err
56+
}
57+
58+
if isTTY {
59+
fmt.Printf("Settings configured for %s\n\n", host)
60+
}
61+
62+
configOptions := config.ConfigOptions()
63+
64+
for _, key := range configOptions {
65+
val, err := cfg.Get(opts.Hostname, key.Key)
66+
if err != nil {
67+
return err
68+
}
69+
fmt.Printf("%s: %s\n", key.Key, val)
70+
}
71+
72+
return nil
73+
}

0 commit comments

Comments
 (0)
X Tutup