forked from scaleway/scaleway-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseealso.go
More file actions
71 lines (56 loc) · 1.62 KB
/
seealso.go
File metadata and controls
71 lines (56 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package qa
import (
"fmt"
"strings"
"github.com/scaleway/scaleway-cli/v2/core"
)
type CommandInvalidSeeAlsoError struct {
Command *core.Command
SeeAlsoCommand string
}
func (err CommandInvalidSeeAlsoError) Error() string {
return fmt.Sprintf("command has invalid see_also commands, '%s' has '%s'",
err.Command.GetCommandLine("scw"),
err.SeeAlsoCommand,
)
}
// testArgSpecInvalidError tests that all commands' see_also commands exist.
func testCommandInvalidSeeAlsoError(commands *core.Commands) []error {
errors := []error(nil)
for _, command := range commands.GetAll() {
for _, seeAlso := range command.SeeAlsos {
seeAlsoCommand := strings.Fields(seeAlso.Command)
// Only check scw commands
if len(seeAlsoCommand) <= 1 || seeAlsoCommand[0] != "scw" {
continue
}
seeAlsoCommand = seeAlsoCommand[1:]
if commands.Find(seeAlsoCommand...) == nil {
errors = append(errors, &CommandInvalidSeeAlsoError{
Command: command,
SeeAlsoCommand: seeAlso.Command,
})
}
}
}
return errors
}
type MissingSeeAlsoError struct {
Command *core.Command
}
func (err MissingSeeAlsoError) Error() string {
return fmt.Sprintf("command has no see_also commands '%s'",
err.Command.GetCommandLine("scw"),
)
}
// testAtLeastOneSeeAlsoIsPresentError testes that there is at least one SeeAlso defined by command
func testAtLeastOneSeeAlsoIsPresentError(commands *core.Commands) []error {
errors := []error(nil)
for _, command := range commands.GetAll() {
if len(command.SeeAlsos) == 0 {
errors = append(errors, &MissingSeeAlsoError{Command: command})
continue
}
}
return errors
}