Skip to content

Commit 27f1852

Browse files
committed
feat(core): handle display oneof (scaleway#3728)
1 parent 9b172ce commit 27f1852

4 files changed

+39
-15
lines changed

cmd/scw/testdata/test-all-usage-alias-create-usage.golden

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ EXAMPLES:
1313
scw alias create c command=create
1414

1515
ARGS:
16-
alias Alias name
17-
[command] Command to create an alias for
16+
alias Alias name
17+
command (one of):
18+
[command] Command to create an alias for
1819

1920
FLAGS:
2021
-h, --help help for create

cmd/scw/testdata/test-all-usage-baremetal-server-install-usage.golden

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ EXAMPLES:
1010
scw baremetal server install 11111111-1111-1111-1111-111111111111 os-id=11111111-1111-1111-1111-111111111111 ssh-key-ids.0=11111111-1111-1111-1111-111111111111
1111

1212
ARGS:
13-
server-id Server ID to install
14-
os-id ID of the OS to installation on the server
15-
hostname Hostname of the server
16-
[all-ssh-keys] Add all SSH keys on your baremetal instance (cannot be used with ssh-key-ids)
17-
ssh-key-ids.{index} SSH key IDs authorized on the server (cannot be used with all-ssh-keys)
18-
[user] User used for the installation
19-
[password] Password used for the installation
20-
[service-user] User used for the service to install
21-
[service-password] Password used for the service to install
22-
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | nl-ams-1 | nl-ams-2)
13+
server-id Server ID to install
14+
os-id ID of the OS to installation on the server
15+
hostname Hostname of the server
16+
ssh (one of):
17+
[all-ssh-keys] Add all SSH keys on your baremetal instance (cannot be used with ssh-key-ids)
18+
ssh-key-ids.{index} SSH key IDs authorized on the server (cannot be used with all-ssh-keys)
19+
[user] User used for the installation
20+
[password] Password used for the installation
21+
[service-user] User used for the service to install
22+
[service-password] Password used for the service to install
23+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | nl-ams-1 | nl-ams-2)
2324

2425
FLAGS:
2526
-h, --help help for install

cmd/scw/testdata/test-all-usage-instance-ssh-remove-key-usage.golden

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ USAGE:
88
scw instance ssh remove-key [arg=value ...]
99

1010
ARGS:
11-
server-id Server to add your key to
12-
[name] Name of the key you want to remove, has to be the key comment or the index
13-
[public-key] Public key you want to remove
11+
server-id Server to add your key to
12+
identifier (one of):
13+
[name] Name of the key you want to remove, has to be the key comment or the index
14+
[public-key] Public key you want to remove
1415
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3)
1516

1617
FLAGS:

internal/core/cobra_usage_builder.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,27 @@ func BuildUsageArgs(ctx context.Context, cmd *Command, deprecated bool) string {
6565
// _buildUsageArgs builds the arg usage list.
6666
// This should not be called directly.
6767
func _buildUsageArgs(ctx context.Context, w io.Writer, argSpecs ArgSpecs) error {
68+
inOneOfGroup := false
69+
lastOneOfGroup := ""
70+
6871
for _, argSpec := range argSpecs {
6972
argSpecUsageLeftPart := argSpec.Name
7073
argSpecUsageRightPart := _buildArgShort(argSpec)
74+
75+
if argSpec.OneOfGroup != "" {
76+
if argSpec.OneOfGroup != lastOneOfGroup {
77+
inOneOfGroup = true
78+
lastOneOfGroup = argSpec.OneOfGroup
79+
_, err := fmt.Fprintf(w, " %s (one of):\n", argSpec.OneOfGroup)
80+
if err != nil {
81+
return err
82+
}
83+
}
84+
} else {
85+
inOneOfGroup = false
86+
lastOneOfGroup = ""
87+
}
88+
7189
if argSpec.Default != nil {
7290
_, doc := argSpec.Default(ctx)
7391
argSpecUsageLeftPart = fmt.Sprintf("%s=%s", argSpecUsageLeftPart, doc)
@@ -78,6 +96,9 @@ func _buildUsageArgs(ctx context.Context, w io.Writer, argSpecs ArgSpecs) error
7896
if argSpec.CanLoadFile {
7997
argSpecUsageRightPart += " (Support file loading with @/path/to/file)"
8098
}
99+
if inOneOfGroup {
100+
argSpecUsageLeftPart = " " + argSpecUsageLeftPart
101+
}
81102

82103
_, err := fmt.Fprintf(w, " %s\t%s\n", argSpecUsageLeftPart, argSpecUsageRightPart)
83104
if err != nil {

0 commit comments

Comments
 (0)