Skip to content

Commit

Permalink
feat(qa): add a qa about commands without examples (#1298)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Cano <[email protected]>
  • Loading branch information
remyleone and kindermoumoute authored Aug 11, 2020
1 parent b79435a commit b6bff44
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions internal/qa/qa.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func LintCommands(commands *core.Commands) []error {
errors = append(errors, testExampleCanHaveOnlyOneTypeOfExampleError(commands)...)
errors = append(errors, testDifferentLocalizationForNamespaceError(commands)...)
errors = append(errors, testDuplicatedCommandError(commands)...)
errors = append(errors, testAtLeastOneExampleIsPresentError(commands)...)

errors = filterIgnore(errors)

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

return errors
}

type MissingExampleError struct {
Command *core.Command
}

func (err MissingExampleError) Error() string {
return fmt.Sprintf("command without examples '%s'", err.Command.GetCommandLine("scw"))
}

// testDuplicatedCommandError testes that there is no duplicate command.
func testAtLeastOneExampleIsPresentError(commands *core.Commands) []error {
errors := []error(nil)

for _, command := range commands.GetAll() {
// Namespace and resources commands do not need examples
// We focus on command with a verb
if command.Run == nil {
continue
}

if len(command.Examples) == 0 {
errors = append(errors, &MissingExampleError{Command: command})
continue
}
}

return errors
}

0 comments on commit b6bff44

Please sign in to comment.