From cacaace969ab71cfa8815a06590c3e0b03501ee6 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sun, 29 Dec 2024 17:31:07 +0900 Subject: [PATCH] fix: don't append ... for fields with an explicit type Fixes #346 --- kong_test.go | 15 +++++++++++++++ model.go | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/kong_test.go b/kong_test.go index fce739a..66ad847 100644 --- a/kong_test.go +++ b/kong_test.go @@ -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, "...") +} diff --git a/model.go b/model.go index f15e6fb..065fcdd 100644 --- a/model.go +++ b/model.go @@ -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