Skip to content

Commit b6bff44

Browse files
feat(qa): add a qa about commands without examples (#1298)
Co-authored-by: Olivier Cano <kindermoumoute@users.noreply.github.com>
1 parent b79435a commit b6bff44

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

internal/qa/qa.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func LintCommands(commands *core.Commands) []error {
1818
errors = append(errors, testExampleCanHaveOnlyOneTypeOfExampleError(commands)...)
1919
errors = append(errors, testDifferentLocalizationForNamespaceError(commands)...)
2020
errors = append(errors, testDuplicatedCommandError(commands)...)
21+
errors = append(errors, testAtLeastOneExampleIsPresentError(commands)...)
2122

2223
errors = filterIgnore(errors)
2324

@@ -318,3 +319,31 @@ func testDuplicatedCommandError(commands *core.Commands) []error {
318319

319320
return errors
320321
}
322+
323+
type MissingExampleError struct {
324+
Command *core.Command
325+
}
326+
327+
func (err MissingExampleError) Error() string {
328+
return fmt.Sprintf("command without examples '%s'", err.Command.GetCommandLine("scw"))
329+
}
330+
331+
// testDuplicatedCommandError testes that there is no duplicate command.
332+
func testAtLeastOneExampleIsPresentError(commands *core.Commands) []error {
333+
errors := []error(nil)
334+
335+
for _, command := range commands.GetAll() {
336+
// Namespace and resources commands do not need examples
337+
// We focus on command with a verb
338+
if command.Run == nil {
339+
continue
340+
}
341+
342+
if len(command.Examples) == 0 {
343+
errors = append(errors, &MissingExampleError{Command: command})
344+
continue
345+
}
346+
}
347+
348+
return errors
349+
}

0 commit comments

Comments
 (0)