Deprecate HelpFormatter.

This commit is contained in:
Alec Thomas
2021-12-03 11:47:34 +11:00
parent c3703cda7e
commit c5e464a367
3 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -599,7 +599,7 @@ The default help output is usually sufficient, but if not there are two solution
1. Use `ConfigureHelp(HelpOptions)` to configure how help is formatted (see [HelpOptions](https://godoc.org/github.com/alecthomas/kong#HelpOptions) for details).
2. Custom help can be wired into Kong via the `Help(HelpFunc)` option. The `HelpFunc` is passed a `Context`, which contains the parsed context for the current command-line. See the implementation of `PrintHelp` for an example.
3. Use `HelpFormatter(HelpValueFormatter)` if you want to just customize the help text that is accompanied by flags and arguments.
3. Use `ValueFormatter(HelpValueFormatter)` if you want to just customize the help text that is accompanied by flags and arguments.
4. Use `Groups([]Group)` if you want to customize group titles or add a header.
### `Bind(...)` - bind values for callback hooks and Run() methods
+2 -2
View File
@@ -477,7 +477,7 @@ func TestEnvarAutoHelpWithEnvPrefix(t *testing.T) {
require.Contains(t, w.String(), "A different flag.")
}
func TestCustomHelpFormatter(t *testing.T) {
func TestCustomValueFormatter(t *testing.T) {
var cli struct {
Flag string `env:"FLAG" help:"A flag."`
}
@@ -485,7 +485,7 @@ func TestCustomHelpFormatter(t *testing.T) {
p := mustNew(t, &cli,
kong.Writers(w, w),
kong.Exit(func(int) {}),
kong.HelpFormatter(func(value *kong.Value) string {
kong.ValueFormatter(func(value *kong.Value) string {
return value.Help
}),
)
+10
View File
@@ -215,6 +215,8 @@ func ShortHelp(shortHelp HelpPrinter) Option {
}
// HelpFormatter configures how the help text is formatted.
//
// Deprecated: Use ValueFormatter() instead.
func HelpFormatter(helpFormatter HelpValueFormatter) Option {
return OptionFunc(func(k *Kong) error {
k.helpFormatter = helpFormatter
@@ -222,6 +224,14 @@ func HelpFormatter(helpFormatter HelpValueFormatter) Option {
})
}
// ValueFormatter configures how the help text is formatted.
func ValueFormatter(helpFormatter HelpValueFormatter) Option {
return OptionFunc(func(k *Kong) error {
k.helpFormatter = helpFormatter
return nil
})
}
// ConfigureHelp sets the HelpOptions to use for printing help.
func ConfigureHelp(options HelpOptions) Option {
return OptionFunc(func(k *Kong) error {