|
1 | 1 | package iam
|
2 | 2 |
|
3 |
| -import "github.com/scaleway/scaleway-cli/v2/internal/core" |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/scaleway/scaleway-cli/v2/internal/core" |
| 7 | +) |
4 | 8 |
|
5 | 9 | func GetCommands() *core.Commands {
|
6 | 10 | cmds := GetGeneratedCommands()
|
7 | 11 |
|
| 12 | + // These commands have an "optional" organization-id that is required for now. |
| 13 | + for _, commandPath := range [][]string{ |
| 14 | + {"iam", "group", "list"}, |
| 15 | + {"iam", "api-key", "list"}, |
| 16 | + {"iam", "ssh-key", "list"}, |
| 17 | + {"iam", "user", "list"}, |
| 18 | + {"iam", "policy", "list"}, |
| 19 | + {"iam", "application", "list"}, |
| 20 | + } { |
| 21 | + cmds.MustFind(commandPath...).Override(setOrganizationDefaultValue) |
| 22 | + } |
| 23 | + |
8 | 24 | return cmds
|
9 | 25 | }
|
| 26 | + |
| 27 | +func setOrganizationDefaultValue(c *core.Command) *core.Command { |
| 28 | + c.ArgSpecs.GetByName("organization-id").Default = func(ctx context.Context) (value string, doc string) { |
| 29 | + organizationID := core.GetOrganizationIDFromContext(ctx) |
| 30 | + return organizationID, "<retrieved from config>" |
| 31 | + } |
| 32 | + return c |
| 33 | +} |
0 commit comments