File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments