Skip to content

Commit 9680fd8

Browse files
author
mritd
committed
feat(context): support interactive set context
support interactive set context refs #11 Signed-off-by: mritd <[email protected]>
1 parent 84829e4 commit 9680fd8

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

cmd/ctx.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ var ctxCmd = &cobra.Command{
1212
Long: `
1313
Change current context.`,
1414
Run: func(cmd *cobra.Command, args []string) {
15-
_ = cmd.Help()
15+
if len(args) == 0 {
16+
mmh.InteractiveSetContext()
17+
} else {
18+
_ = cmd.Help()
19+
}
1620
},
1721
}
1822

mmh/mmh.go

+21
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,24 @@ func InteractiveLogin() {
3636
idx := s.Run()
3737
SingleLogin(CurrentContext.Servers[idx].Name)
3838
}
39+
40+
func InteractiveSetContext() {
41+
cfg := &promptx.SelectConfig{
42+
ActiveTpl: `» {{ .Name | cyan }}`,
43+
InactiveTpl: ` {{ .Name | white }}`,
44+
SelectPrompt: "Context",
45+
SelectedTpl: `{{ "» " | green }}{{ .Name | green }}`,
46+
DisPlaySize: 9,
47+
DetailsTpl: `
48+
--------- Context ----------
49+
{{ "Name:" | faint }} {{ .Name | faint }}
50+
{{ "ConfigPath:" | faint }} {{ .ConfigPath | faint }}`,
51+
}
52+
53+
s := &promptx.Select{
54+
Items: Main.Contexts,
55+
Config: cfg,
56+
}
57+
idx := s.Run()
58+
UseContext(Main.Contexts[idx].Name)
59+
}

version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.3.4
1+
v1.3.5

0 commit comments

Comments
 (0)