-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_override_help_test.go
71 lines (64 loc) · 1.6 KB
/
example_override_help_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package warg_test
import (
"fmt"
"go.bbkane.com/warg"
"go.bbkane.com/warg/command"
"go.bbkane.com/warg/flag"
"go.bbkane.com/warg/help"
"go.bbkane.com/warg/help/common"
"go.bbkane.com/warg/help/detailed"
"go.bbkane.com/warg/section"
)
func exampleOverrideHelpFlaglogin(_ command.Context) error {
fmt.Println("Logging in")
return nil
}
func exampleOverrideHelpFlagCustomCommandHelp(_ *command.Command, _ common.HelpInfo) command.Action {
return func(ctx command.Context) error {
file := ctx.Stdout
fmt.Fprintln(file, "Custom command help")
return nil
}
}
func exampleOverrideHelpFlagCustomSectionHelp(_ *section.SectionT, _ common.HelpInfo) command.Action {
return func(ctx command.Context) error {
file := ctx.Stdout
fmt.Fprintln(file, "Custom section help")
return nil
}
}
func ExampleOverrideHelpFlag() {
app := warg.New(
"newAppName",
section.New(
"work with a fictional blog platform",
section.Command(
"login",
"Login to the platform",
exampleOverrideHelpFlaglogin,
),
),
warg.OverrideHelpFlag(
[]help.HelpFlagMapping{
{
Name: "default",
CommandHelp: detailed.DetailedCommandHelp,
SectionHelp: detailed.DetailedSectionHelp,
},
{
Name: "custom",
CommandHelp: exampleOverrideHelpFlagCustomCommandHelp,
SectionHelp: exampleOverrideHelpFlagCustomSectionHelp,
},
},
"default",
"--help",
"Print help",
flag.Alias("-h"),
// the flag default should match a name in the HelpFlagMapping
),
)
app.MustRun(warg.OverrideArgs([]string{"blog.exe", "-h", "custom"}))
// Output:
// Custom section help
}