Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) < 1 {
Comment thread
remyleone marked this conversation as resolved.
Outdated
errors = append(errors, &MissingExampleError{Command: command})
continue
}
}

return errors
}