Skip to content

Commit

Permalink
fix: update the aliases when OptProxy sets the aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Mar 1, 2022
1 parent 65f6617 commit ce2d262
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion opt_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (o *OptProxy) IsCli(cli bool) *OptProxy {

// Aliases appends the aliases of the option and returns itself.
func (o *OptProxy) Aliases(aliases ...string) *OptProxy {
o.option.opt = o.option.opt.As(aliases...)
for _, alias := range aliases {
o.config.setOptAlias(alias, o.option.opt.Name)
}
return o
}

Expand Down
16 changes: 16 additions & 0 deletions opt_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,19 @@ func TestOptProxyOnUpdate(t *testing.T) {
t.Errorf("expect '%s', but got '%s'", expect, s)
}
}

func TestOptProxyAliases(t *testing.T) {
config := New()
opt := config.NewString("newopt", "abc", "help").Aliases("oldopt")

if v := opt.Get(); v != "abc" {
t.Errorf("expect '%s', but got '%s'", "abc", v)
}

err := config.Set("oldopt", "xyz")
if err != nil {
t.Error(err)
} else if v := opt.Get(); v != "xyz" {
t.Errorf("expect '%s', but got '%s'", "xyz", v)
}
}

0 comments on commit ce2d262

Please sign in to comment.