Skip to content

Commit

Permalink
[Bug] fix #2532
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Feb 15, 2024
1 parent e821fe9 commit df5f883
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
14 changes: 14 additions & 0 deletions internal/config/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ func NewAliases() *Aliases {
}
}

func (a *Aliases) AliasesFor(s string) []string {
aa := make([]string, 0, 10)

a.mx.RLock()
defer a.mx.RUnlock()
for k, v := range a.Alias {
if v == s {
aa = append(aa, k)
}
}

return aa
}

// Keys returns all aliases keys.
func (a *Aliases) Keys() []string {
a.mx.RLock()
Expand Down
4 changes: 4 additions & 0 deletions internal/dao/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func NewAlias(f Factory) *Alias {
return &a
}

func (a *Alias) AliasesFor(s string) []string {
return a.Aliases.AliasesFor(s)
}

// Check verifies an alias is defined for this command.
func (a *Alias) Check(cmd string) (string, bool) {
return a.Aliases.Get(cmd)
Expand Down
16 changes: 8 additions & 8 deletions internal/view/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ func NewCommand(app *App) *Command {

// AliasesFor gather all known aliases for a given resource.
func (c *Command) AliasesFor(s string) []string {
aa := make([]string, 0, 10)
for k, v := range c.alias.Alias {
if v == s {
aa = append(aa, k)
}
}

return aa
return c.alias.AliasesFor(s)
}

// Init initializes the command.
Expand Down Expand Up @@ -163,6 +156,13 @@ func (c *Command) run(p *cmd.Interpreter, fqn string, clearStack bool) error {
}

if context, ok := p.HasContext(); ok {
if context != c.app.Config.ActiveContextName() {
if err := c.app.Config.Save(); err != nil {
log.Error().Err(err).Msg("config save failed!")
} else {
log.Debug().Msgf("Saved context config for: %q", context)
}
}
res, err := dao.AccessorFor(c.app.factory, client.NewGVR("contexts"))
if err != nil {
return err
Expand Down

0 comments on commit df5f883

Please sign in to comment.