Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 15bd306

Browse files
committed
Removing: example cannot be parsed correctly at this time
1 parent d59b6bd commit 15bd306

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func commandFromScript(path string) (*cobra.Command, error) {
253253
RunE: execCommand,
254254
}
255255

256-
example, err := exampleFrom(path, cmd)
256+
example, err := exampleFrom(path)
257257
if err != nil {
258258
return nil, err
259259
}

cli/cli_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func TestCommandFromScript(t *testing.T) {
155155
assert.NoError(t, err)
156156
assert.Equal(t, filepath.Base(f.Name()), c.Use)
157157
assert.Equal(t, "blah", c.Short)
158-
assert.Regexp(t, " test-command-from-script(.*?) one two three", c.Example)
158+
assert.Equal(t, " one two three", c.Example)
159159
assert.Equal(t, f.Name(), c.Annotations["Source"])
160160
})
161161
}

cli/parsing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Looks for a line like this:
109109
# example: foo bar 1 2 3
110110
111111
*/
112-
func exampleFrom(path string, cmd *cobra.Command) (string, error) {
112+
func exampleFrom(path string) (string, error) {
113113
file, err := os.Open(path)
114114
if err != nil {
115115
return "", err
@@ -127,7 +127,7 @@ func exampleFrom(path string, cmd *cobra.Command) (string, error) {
127127
match := r.FindStringSubmatch(scanner.Text())
128128
if len(match) == 2 {
129129
logrus.Debug("Found example line: ", filepath.Join(path), ", set to: ", match[1])
130-
return fmt.Sprintf(" %s %s", cmd.UseLine(), match[1]), nil
130+
return fmt.Sprintf(" %s", match[1]), nil
131131
}
132132
}
133133
return "", nil

cli/parsing_test.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,37 +198,21 @@ func TestUsageFrom(t *testing.T) {
198198
func TestExampleFrom(t *testing.T) {
199199
var tests = []struct {
200200
name string
201-
alias string
202201
input string
203202
expected string
204203
}{
205204
{
206205
"happy path",
207-
"sd",
208206
"#\n# example: blah\n#\n",
209-
" sd blah",
207+
" blah",
210208
},
211209
{
212210
"missing",
213-
"sd",
214-
"#\n#\n#\n",
215-
"",
216-
},
217-
{
218-
"happy path (aliased)",
219-
"foo",
220-
"#\n# example: blah\n#\n",
221-
" foo blah",
222-
},
223-
{
224-
"missing (aliased)",
225-
"foo",
226211
"#\n#\n#\n",
227212
"",
228213
},
229214
{
230215
"no input",
231-
"sd",
232216
"",
233217
"",
234218
},
@@ -245,7 +229,7 @@ func TestExampleFrom(t *testing.T) {
245229
_ = os.Remove(f.Name())
246230
}()
247231

248-
v, err := exampleFrom(f.Name(), &cobra.Command{Use: test.alias})
232+
v, err := exampleFrom(f.Name())
249233
assert.NoError(t, err)
250234
assert.Equal(t, test.expected, v)
251235
})

0 commit comments

Comments
 (0)