Skip to content

Commit 5c26a53

Browse files
author
mritd
committed
feat(config): update find contexts
update find contexts Signed-off-by: mritd <[email protected]>
1 parent fd24720 commit 5c26a53

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cmd/root.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func initConfig() {
6666
}
6767

6868
// get current use context
69-
ctx, ok := mmh.Main.Contexts.FindContextByName(mmh.Main.Current)
69+
ctx, ok := mmh.FindContextByName(mmh.Main.Current)
7070
if !ok {
7171
utils.Exit(fmt.Sprintf("could not found current context: %s\n", mmh.Main.Current), 1)
7272
}
@@ -87,7 +87,7 @@ func initConfig() {
8787
utils.CheckAndExit(mmh.CurrentContext.LoadFrom(ctxConfigFile))
8888

8989
// get current use context
90-
basicCtx, ok := mmh.Main.Contexts.FindContextByName(mmh.Main.Basic)
90+
basicCtx, ok := mmh.FindContextByName(mmh.Main.Basic)
9191
if ok {
9292
if filepath.IsAbs(basicCtx.ConfigPath) {
9393
ctxConfigFile = basicCtx.ConfigPath

mmh/config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ var (
3535
)
3636

3737
// find context by name
38-
func (cs Contexts) FindContextByName(name string) (Context, bool) {
39-
for _, ctx := range cs {
38+
func FindContextByName(name string) (Context, bool) {
39+
for _, ctx := range Main.Contexts {
4040
if name == ctx.Name {
4141
return ctx, true
4242
}
@@ -406,7 +406,7 @@ func ListContexts() {
406406

407407
// set current context
408408
func UseContext(ctxName string) {
409-
_, ok := Main.Contexts.FindContextByName(ctxName)
409+
_, ok := FindContextByName(ctxName)
410410
if !ok {
411411
utils.Exit(fmt.Sprintf("context [%s] not found", ctxName), 1)
412412
}

0 commit comments

Comments
 (0)