-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontext_list.go
More file actions
48 lines (40 loc) · 1.26 KB
/
context_list.go
File metadata and controls
48 lines (40 loc) · 1.26 KB
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
package context
import (
"github.com/spf13/cobra"
"github.com/stackvista/stackstate-cli/internal/common"
"github.com/stackvista/stackstate-cli/internal/config"
"github.com/stackvista/stackstate-cli/internal/di"
"github.com/stackvista/stackstate-cli/internal/printer"
)
func ListCommand(deps *di.Deps) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List all configured connection contexts",
Long: "List all connection contexts saved in the CLI configuration file, showing the context name and server URL for each.",
Example: `# list all contexts
sts context list
# list contexts in JSON format
sts context list -o json`,
RunE: deps.CmdRunEWithConfig(RunContextListCommand),
}
return cmd
}
func RunContextListCommand(cli *di.Deps, cmd *cobra.Command, cfg *config.Config) common.CLIError {
ctxs := cfg.Contexts
if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"contexts": ctxs,
})
} else {
data := make([][]interface{}, 0)
for _, ctx := range ctxs {
data = append(data, []interface{}{ctx.Name, ctx.Context.URL})
}
cli.Printer.Table(printer.TableData{
Header: []string{"name", "url"},
Data: data,
MissingTableDataMsg: printer.NotFoundMsg{Types: "contexts"},
})
}
return nil
}