File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ package qa
2+
3+ import (
4+ "encoding/json"
5+ "fmt"
6+
7+ "github.com/scaleway/scaleway-cli/v2/internal/core"
8+ )
9+
10+ type CommandInvalidJSONExampleError struct {
11+ Command * core.Command
12+ }
13+
14+ func (err CommandInvalidJSONExampleError ) Error () string {
15+ return fmt .Sprintf ("command has invalid json examples '%s'" ,
16+ err .Command .GetCommandLine ("scw" ),
17+ )
18+ }
19+
20+ // testArgSpecInvalidError tests that all argspecs have a corresponding in their command's argstype.
21+ func testCommandInvalidJSONExampleError (commands * core.Commands ) []error {
22+ errors := []error (nil )
23+
24+ for _ , command := range commands .GetAll () {
25+ for _ , example := range command .Examples {
26+ if example .ArgsJSON != "" {
27+ out := map [string ]any {}
28+ err := json .Unmarshal ([]byte (example .ArgsJSON ), & out )
29+ if err != nil {
30+ errors = append (errors , & CommandInvalidJSONExampleError {
31+ Command : command ,
32+ })
33+ }
34+ }
35+ }
36+ }
37+
38+ return errors
39+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ func LintCommands(commands *core.Commands) []error {
2121 errors = append (errors , testAtLeastOneExampleIsPresentError (commands )... )
2222 errors = append (errors , testArgSpecInvalidError (commands )... )
2323 errors = append (errors , testArgSpecMissingError (commands )... )
24+ errors = append (errors , testCommandInvalidJSONExampleError (commands )... )
2425
2526 errors = filterIgnore (errors )
2627
You can’t perform that action at this time.
0 commit comments