fix: don't append ... for fields with an explicit type

Fixes #346
This commit is contained in:
Alec Thomas
2024-12-29 17:31:07 +09:00
parent a32b94b705
commit cacaace969
2 changed files with 17 additions and 2 deletions
+15
View File
@@ -2460,3 +2460,18 @@ func TestApplyCalledOnce(t *testing.T) {
err = kctx.Run()
assert.NoError(t, err)
}
func TestCustomTypeNoEllipsis(t *testing.T) {
type CLI struct {
Flag []byte `type:"existingfile"`
}
var cli CLI
p := mustNew(t, &cli, kong.Exit(func(int) {}))
w := &strings.Builder{}
p.Stderr = w
p.Stdout = w
_, err := p.Parse([]string{"--help"})
assert.NoError(t, err)
help := w.String()
assert.NotContains(t, help, "...")
}
+2 -2
View File
@@ -433,7 +433,7 @@ func (f *Flag) FormatPlaceHolder() string {
return placeholderHelper.PlaceHolder(f)
}
tail := ""
if f.Value.IsSlice() && f.Value.Tag.Sep != -1 {
if f.Value.IsSlice() && f.Value.Tag.Sep != -1 && f.Tag.Type == "" {
tail += string(f.Value.Tag.Sep) + "..."
}
if f.PlaceHolder != "" {
@@ -446,7 +446,7 @@ func (f *Flag) FormatPlaceHolder() string {
return f.Default + tail
}
if f.Value.IsMap() {
if f.Value.Tag.MapSep != -1 {
if f.Value.Tag.MapSep != -1 && f.Tag.Type == "" {
tail = string(f.Value.Tag.MapSep) + "..."
}
return "KEY=VALUE" + tail