Repository: alecthomas/kong (go)

Issue:
Specifying default overrides placeholder
I have:

```
var CLI struct {
	Changelog string `short:"f" placeholder:"PATH" default:"CHANGELOG.md" help:"Path to the changelog file to use."`
}
```

The help message is:

```
-f, --changelog="CHANGELOG.md"    Path to the changelog file to use.
```

I would expect it would be:

```
-f, --changelog=PATH    Path to the changelog file to use.
```

My plan is to show default value in the help message using variable interpolation.

Pull request description:
Fix that default should not override the placeholder
Fixes #243.

Patch:
diff --git a/model.go b/model.go
index bc7f37e..2c2991f 100644
--- a/model.go
+++ b/model.go
@@ -400,21 +400,24 @@ func (f *Flag) FormatPlaceHolder() string {
 	if f.Value.IsSlice() && f.Value.Tag.Sep != -1 {
 		tail += string(f.Value.Tag.Sep) + "..."
 	}
+	if f.PlaceHolder != "" {
+		return f.PlaceHolder + tail
+	}
 	if f.Default != "" {
 		if f.Value.Target.Kind() == reflect.String {
 			return strconv.Quote(f.Default) + tail
 		}
 		return f.Default + tail
 	}
-	if f.PlaceHolder != "" {
-		return f.PlaceHolder + tail
-	}
 	if f.Value.IsMap() {
 		if f.Value.Tag.MapSep != -1 {
 			tail = string(f.Value.Tag.MapSep) + "..."
 		}
 		return "KEY=VALUE" + tail
 	}
+	if f.Tag != nil && f.Tag.TypeName != "" {
+		return strings.ToUpper(dashedString(f.Tag.TypeName)) + tail
+	}
 	return strings.ToUpper(f.Name) + tail
 }
 
diff --git a/tag.go b/tag.go
index 03b8ca6..d76c418 100644
--- a/tag.go
+++ b/tag.go
@@ -19,6 +19,7 @@ type Tag struct {
 	Name        string
 	Help        string
 	Type        string
+	TypeName    string
 	Default     string
 	Format      string
 	PlaceHolder string
@@ -183,6 +184,7 @@ func hydrateTag(t *Tag, typeName string, isBool bool) error {
 	t.Name = t.Get("name")
 	t.Help = t.Get("help")
 	t.Type = t.Get("type")
+	t.TypeName = typeName
 	t.Env = t.Get("env")
 	t.Short, err = t.GetRune("short")
 	if err != nil && t.Get("short") != "" {
@@ -217,9 +219,6 @@ func hydrateTag(t *Tag, typeName string, isBool bool) error {
 		t.Vars[parts[0]] = parts[1]
 	}
 	t.PlaceHolder = t.Get("placeholder")
-	if t.PlaceHolder == "" {
-		t.PlaceHolder = strings.ToUpper(dashedString(typeName))
-	}
 	t.Enum = t.Get("enum")
 	if t.Enum != "" && !(t.Required || t.Default != "") {
 		return fmt.Errorf("enum value is only valid if it is either required or has a valid default value")


Test patch:
diff --git a/model_test.go b/model_test.go
index 0edd1b3..1296f3d 100644
--- a/model_test.go
+++ b/model_test.go
@@ -32,6 +32,7 @@ func TestFlagString(t *testing.T) {
 		DefaultInt              int    `default:"42"`
 		DefaultStr              string `default:"hello"`
 		Placeholder             string `placeholder:"world"`
+		DefaultPlaceholder      string `default:"hello" placeholder:"world"`
 		SliceSep                []string
 		SliceNoSep              []string `sep:"none"`
 		SliceDefault            []string `default:"hello"`
@@ -49,11 +50,12 @@ func TestFlagString(t *testing.T) {
 		"default-int":               "--default-int=42",
 		"default-str":               `--default-str="hello"`,
 		"placeholder":               "--placeholder=world",
+		"default-placeholder":       "--default-placeholder=world",
 		"slice-sep":                 "--slice-sep=SLICE-SEP,...",
 		"slice-no-sep":              "--slice-no-sep=SLICE-NO-SEP",
 		"slice-default":             "--slice-default=hello,...",
 		"slice-placeholder":         "--slice-placeholder=world,...",
-		"slice-default-placeholder": "--slice-default-placeholder=hello,...",
+		"slice-default-placeholder": "--slice-default-placeholder=world,...",
 		"map-sep":                   "--map-sep=KEY=VALUE;...",
 		"map-no-sep":                "--map-no-sep=KEY=VALUE",
 		"map-default":               "--map-default=hello",