Skip to content

Commit 32499ba

Browse files
authored
docs: update invalid seealso commands (#3199)
1 parent 89c4747 commit 32499ba

File tree

8 files changed

+59
-12
lines changed

8 files changed

+59
-12
lines changed

cmd/scw/testdata/test-all-usage-config-dump-usage.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ GLOBAL FLAGS:
1616

1717
SEE ALSO:
1818
# Config management help
19-
scw config --help
19+
scw config

cmd/scw/testdata/test-all-usage-config-get-usage.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ GLOBAL FLAGS:
2626

2727
SEE ALSO:
2828
# Config management help
29-
scw config --help
29+
scw config

cmd/scw/testdata/test-all-usage-config-info-usage.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ GLOBAL FLAGS:
2323

2424
SEE ALSO:
2525
# Config management help
26-
scw config --help
26+
scw config

cmd/scw/testdata/test-all-usage-config-set-usage.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ GLOBAL FLAGS:
3535

3636
SEE ALSO:
3737
# Config management help
38-
scw config --help
38+
scw config

internal/namespaces/config/commands.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ func configRoot() *core.Command {
8080
SeeAlsos: []*core.SeeAlso{
8181
{
8282
Short: "Init your Scaleway config",
83-
Command: "scw config init",
83+
Command: "scw init",
8484
},
8585
{
8686
Short: "Set a config attribute",
87-
Command: "scw config set --help",
87+
Command: "scw config set",
8888
},
8989
{
9090
Short: "Set a config attribute",
91-
Command: "scw config get --help",
91+
Command: "scw config get",
9292
},
9393
{
9494
Short: "Dump the config",
@@ -137,7 +137,7 @@ func configGetCommand() *core.Command {
137137
SeeAlsos: []*core.SeeAlso{
138138
{
139139
Short: "Config management help",
140-
Command: "scw config --help",
140+
Command: "scw config",
141141
},
142142
},
143143
Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
@@ -260,7 +260,7 @@ The only allowed attributes are access_key, secret_key, default_organization_id,
260260
SeeAlsos: []*core.SeeAlso{
261261
{
262262
Short: "Config management help",
263-
Command: "scw config --help",
263+
Command: "scw config",
264264
},
265265
},
266266
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
@@ -377,7 +377,7 @@ func configDumpCommand() *core.Command {
377377
SeeAlsos: []*core.SeeAlso{
378378
{
379379
Short: "Config management help",
380-
Command: "scw config --help",
380+
Command: "scw config",
381381
},
382382
},
383383
Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
@@ -574,7 +574,7 @@ func configInfoCommand() *core.Command {
574574
SeeAlsos: []*core.SeeAlso{
575575
{
576576
Short: "Config management help",
577-
Command: "scw config --help",
577+
Command: "scw config",
578578
},
579579
},
580580
Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) {

internal/namespaces/init/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Default path for configuration file is based on the following priority order:
124124
SeeAlsos: []*core.SeeAlso{
125125
{
126126
Short: "Config management help",
127-
Command: "scw config --help",
127+
Command: "scw config",
128128
},
129129
},
130130
Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) {

internal/qa/qa.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func LintCommands(commands *core.Commands) []error {
2222
errors = append(errors, testArgSpecInvalidError(commands)...)
2323
errors = append(errors, testArgSpecMissingError(commands)...)
2424
errors = append(errors, testCommandInvalidJSONExampleError(commands)...)
25+
errors = append(errors, testCommandInvalidSeeAlsoError(commands)...)
2526

2627
errors = filterIgnore(errors)
2728

internal/qa/seealso.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package qa
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/scaleway/scaleway-cli/v2/internal/core"
8+
)
9+
10+
type CommandInvalidSeeAlsoError struct {
11+
Command *core.Command
12+
SeeAlsoCommand string
13+
}
14+
15+
func (err CommandInvalidSeeAlsoError) Error() string {
16+
return fmt.Sprintf("command has invalid see_also commands, '%s' has '%s'",
17+
err.Command.GetCommandLine("scw"),
18+
err.SeeAlsoCommand,
19+
)
20+
}
21+
22+
// testArgSpecInvalidError tests that all commands' see_also commands exist.
23+
func testCommandInvalidSeeAlsoError(commands *core.Commands) []error {
24+
errors := []error(nil)
25+
26+
for _, command := range commands.GetAll() {
27+
for _, seeAlso := range command.SeeAlsos {
28+
seeAlsoCommand := strings.Fields(seeAlso.Command)
29+
30+
// Only check scw commands
31+
if len(seeAlsoCommand) <= 1 || seeAlsoCommand[0] != "scw" {
32+
continue
33+
}
34+
seeAlsoCommand = seeAlsoCommand[1:]
35+
36+
if commands.Find(seeAlsoCommand...) == nil {
37+
errors = append(errors, &CommandInvalidSeeAlsoError{
38+
Command: command,
39+
SeeAlsoCommand: seeAlso.Command,
40+
})
41+
}
42+
}
43+
}
44+
45+
return errors
46+
}

0 commit comments

Comments
 (0)