forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_config.go
99 lines (86 loc) · 2.11 KB
/
get_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package cmd
import (
"io"
"github.com/jenkins-x/jx/pkg/config"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/spf13/cobra"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
)
// GetConfigOptions the command line options
type GetConfigOptions struct {
GetOptions
Dir string
}
var (
getConfigLong = templates.LongDesc(`
Display the project configuration
`)
getConfigExample = templates.Examples(`
# View the project configuration
jx get config
`)
)
// NewCmdGetConfig creates the command
func NewCmdGetConfig(f Factory, out io.Writer, errOut io.Writer) *cobra.Command {
options := &GetConfigOptions{
GetOptions: GetOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "config [flags]",
Short: "Display the project configuration",
Long: getConfigLong,
Example: getConfigExample,
Aliases: []string{"url"},
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
options.addGetConfigFlags(cmd)
return cmd
}
func (o *GetConfigOptions) addGetConfigFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&o.Dir, "dir", "d", "", "The root project directory")
}
// Run implements this command
func (o *GetConfigOptions) Run() error {
pc, _, err := config.LoadProjectConfig(o.Dir)
if err != nil {
return err
}
if pc.IsEmpty() {
log.Infoln("No project configuration for this directory.")
log.Infof("To edit the configuration use: %s\n", util.ColorInfo("jx edit config"))
return nil
}
table := o.CreateTable()
table.AddRow("SERVICE", "KIND", "URL", "NAME")
t := pc.IssueTracker
if t != nil {
table.AddRow("Issue Tracker", t.Kind, t.URL, t.Project)
}
w := pc.Wiki
if w != nil {
table.AddRow("Wiki", w.Kind, w.URL, w.Space)
}
ch := pc.Chat
if ch != nil {
if ch.DeveloperChannel != "" {
table.AddRow("Developer Chat", ch.Kind, ch.URL, ch.DeveloperChannel)
}
if ch.UserChannel != "" {
table.AddRow("User Chat", ch.Kind, ch.URL, ch.UserChannel)
}
}
table.Render()
return nil
}