|
| 1 | +//go:build !urfave_cli_no_docs |
| 2 | +// +build !urfave_cli_no_docs |
| 3 | + |
1 | 4 | package cli |
2 | 5 |
|
3 | 6 | import ( |
4 | | - "bytes" |
5 | 7 | "errors" |
6 | | - "io/ioutil" |
7 | 8 | "testing" |
8 | 9 | ) |
9 | 10 |
|
10 | | -func testApp() *App { |
11 | | - app := newTestApp() |
12 | | - app.Name = "greet" |
13 | | - app.Flags = []Flag{ |
14 | | - &StringFlag{ |
15 | | - Name: "socket", |
16 | | - Aliases: []string{"s"}, |
17 | | - Usage: "some 'usage' text", |
18 | | - Value: "value", |
19 | | - TakesFile: true, |
20 | | - }, |
21 | | - &StringFlag{Name: "flag", Aliases: []string{"fl", "f"}}, |
22 | | - &BoolFlag{ |
23 | | - Name: "another-flag", |
24 | | - Aliases: []string{"b"}, |
25 | | - Usage: "another usage text", |
26 | | - }, |
27 | | - &BoolFlag{ |
28 | | - Name: "hidden-flag", |
29 | | - Hidden: true, |
30 | | - }, |
31 | | - } |
32 | | - app.Commands = []*Command{{ |
33 | | - Aliases: []string{"c"}, |
34 | | - Flags: []Flag{ |
35 | | - &StringFlag{ |
36 | | - Name: "flag", |
37 | | - Aliases: []string{"fl", "f"}, |
38 | | - TakesFile: true, |
39 | | - }, |
40 | | - &BoolFlag{ |
41 | | - Name: "another-flag", |
42 | | - Aliases: []string{"b"}, |
43 | | - Usage: "another usage text", |
44 | | - }, |
45 | | - }, |
46 | | - Name: "config", |
47 | | - Usage: "another usage test", |
48 | | - Subcommands: []*Command{{ |
49 | | - Aliases: []string{"s", "ss"}, |
50 | | - Flags: []Flag{ |
51 | | - &StringFlag{Name: "sub-flag", Aliases: []string{"sub-fl", "s"}}, |
52 | | - &BoolFlag{ |
53 | | - Name: "sub-command-flag", |
54 | | - Aliases: []string{"s"}, |
55 | | - Usage: "some usage text", |
56 | | - }, |
57 | | - }, |
58 | | - Name: "sub-config", |
59 | | - Usage: "another usage test", |
60 | | - }}, |
61 | | - }, { |
62 | | - Aliases: []string{"i", "in"}, |
63 | | - Name: "info", |
64 | | - Usage: "retrieve generic information", |
65 | | - }, { |
66 | | - Name: "some-command", |
67 | | - }, { |
68 | | - Name: "hidden-command", |
69 | | - Hidden: true, |
70 | | - }, { |
71 | | - Aliases: []string{"u"}, |
72 | | - Flags: []Flag{ |
73 | | - &StringFlag{ |
74 | | - Name: "flag", |
75 | | - Aliases: []string{"fl", "f"}, |
76 | | - TakesFile: true, |
77 | | - }, |
78 | | - &BoolFlag{ |
79 | | - Name: "another-flag", |
80 | | - Aliases: []string{"b"}, |
81 | | - Usage: "another usage text", |
82 | | - }, |
83 | | - }, |
84 | | - Name: "usage", |
85 | | - Usage: "standard usage text", |
86 | | - UsageText: ` |
87 | | -Usage for the usage text |
88 | | -- formatted: Based on the specified ConfigMap and summon secrets.yml |
89 | | -- list: Inspect the environment for a specific process running on a Pod |
90 | | -- for_effect: Compare 'namespace' environment with 'local' |
91 | | -
|
92 | | -` + "```" + ` |
93 | | -func() { ... } |
94 | | -` + "```" + ` |
95 | | -
|
96 | | -Should be a part of the same code block |
97 | | -`, |
98 | | - Subcommands: []*Command{{ |
99 | | - Aliases: []string{"su"}, |
100 | | - Flags: []Flag{ |
101 | | - &BoolFlag{ |
102 | | - Name: "sub-command-flag", |
103 | | - Aliases: []string{"s"}, |
104 | | - Usage: "some usage text", |
105 | | - }, |
106 | | - &StringFlag{ |
107 | | - Name: "sub-command-hidden-flag", |
108 | | - Usage: "some hidden usage text", |
109 | | - Hidden: true, |
110 | | - }, |
111 | | - }, |
112 | | - Name: "sub-usage", |
113 | | - Usage: "standard usage text", |
114 | | - UsageText: "Single line of UsageText", |
115 | | - }}, |
116 | | - }} |
117 | | - app.UsageText = "app [first_arg] [second_arg]" |
118 | | - app.Description = `Description of the application.` |
119 | | - app.Usage = "Some app" |
120 | | - app.Authors = []*Author{ |
121 | | - { Name: "Harrison", Email: "[email protected]"}, |
122 | | - { Name: "Oliver Allen", Email: "[email protected]"}, |
123 | | - } |
124 | | - return app |
125 | | -} |
126 | | - |
127 | | -func expectFileContent(t *testing.T, file, got string) { |
128 | | - data, err := ioutil.ReadFile(file) |
129 | | - // Ignore windows line endings |
130 | | - // TODO: Replace with bytes.ReplaceAll when support for Go 1.11 is dropped |
131 | | - data = bytes.Replace(data, []byte("\r\n"), []byte("\n"), -1) |
132 | | - expect(t, err, nil) |
133 | | - expect(t, got, string(data)) |
134 | | -} |
135 | | - |
136 | 11 | func TestToMarkdownFull(t *testing.T) { |
137 | 12 | // Given |
138 | 13 | app := testApp() |
|
0 commit comments