Skip to content

Commit

Permalink
Change --roles to --role, fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique Santos committed Feb 8, 2024
1 parent b3ba358 commit 72272df
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/stackit_mongodbflex_instance_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ stackit mongodbflex instance create [flags]
--ram int Amount of RAM (in GB)
--storage-class string Storage class (default "premium-perf2-mongodb")
--storage-size int Storage size (in GB) (default 10)
--type string Instance type, one of ["Sharded" "Single" "Replica"] (default "Replica")
--type string Instance type, one of ["Single" "Replica" "Sharded"] (default "Replica")
--version string MongoDB version. Defaults to the latest version available
```

Expand Down
2 changes: 1 addition & 1 deletion docs/stackit_mongodbflex_instance_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ stackit mongodbflex instance update INSTANCE_ID [flags]
--ram int Amount of RAM (in GB)
--storage-class string Storage class
--storage-size int Storage size (in GB)
--type string Instance type, one of ["Single" "Replica" "Sharded"]
--type string Instance type, one of ["Sharded" "Single" "Replica"]
--version string Version
```

Expand Down
6 changes: 3 additions & 3 deletions docs/stackit_mongodbflex_user_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ stackit mongodbflex user create [flags]

```
Create a MongoDB Flex user for instance with ID "xxx" and specify the username
$ stackit mongodbflex user create --instance-id xxx --username johndoe --roles read --database default
$ stackit mongodbflex user create --instance-id xxx --username johndoe --role read --database default
Create a MongoDB Flex user for instance with ID "xxx" with an automatically generated username
$ stackit mongodbflex user create --instance-id xxx --roles read --database default
$ stackit mongodbflex user create --instance-id xxx --role read --database default
```

### Options
Expand All @@ -29,7 +29,7 @@ stackit mongodbflex user create [flags]
--database string The database inside the MongoDB instance that the user has access to. If it does not exist, it will be created once the user writes to it
-h, --help Help for "stackit mongodbflex user create"
--instance-id string ID of the instance
--roles strings Roles of the user, possible values are ["read" "readWrite"] (default [read])
--role strings Roles of the user, can be specified multiple times. Possible values are ["read" "readWrite"] (default [])
--username string Username of the user. If not specified, a random username will be assigned
```

Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_mongodbflex_user_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ stackit mongodbflex user update USER_ID [flags]

```
Update the roles of a MongoDB Flex user with ID "xxx" of instance with ID "yyy"
$ stackit mongodbflex user update xxx --instance-id yyy --roles read
$ stackit mongodbflex user update xxx --instance-id yyy --role read
```

### Options
Expand All @@ -23,7 +23,7 @@ stackit mongodbflex user update USER_ID [flags]
--database string The database inside the MongoDB instance that the user has access to. If it does not exist, it will be created once the user writes to it
-h, --help Help for "stackit mongodbflex user update"
--instance-id string ID of the instance
--roles strings Roles of the user, possible values are ["read" "readWrite"] (default [])
--role strings Roles of the user, can be specified multiple times. Possible values are ["read" "readWrite"] (default [])
```

### Options inherited from parent commands
Expand Down
10 changes: 5 additions & 5 deletions docs/stackit_postgresflex_user_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ stackit postgresflex user create [flags]
### Examples

```
Create a PostgreSQL Flex user for instance with ID "xxx" and specify the username
$ stackit postgresflex user create --instance-id xxx --username johndoe --roles read
Create a PostgreSQL Flex user for instance with ID "xxx"
$ stackit postgresflex user create --instance-id xxx --username johndoe
Create a PostgreSQL Flex user for instance with ID "xxx" with an automatically generated username
$ stackit postgresflex user create --instance-id xxx --roles read
Create a PostgreSQL Flex user for instance with ID "xxx" and permission "createdb"
$ stackit postgresflex user create --instance-id xxx --username johndoe --role createdb
```

### Options

```
-h, --help Help for "stackit postgresflex user create"
--instance-id string ID of the instance
--roles strings Roles of the user, possible values are ["login" "createdb"] (default [login])
--role strings Roles of the user, can be specified multiple times. Possible values are ["login" "createdb"] (default [])
--username string Username of the user
```

Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_postgresflex_user_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ stackit postgresflex user update USER_ID [flags]

```
Update the roles of a PostgreSQL Flex user with ID "xxx" of instance with ID "yyy"
$ stackit postgresflex user update xxx --instance-id yyy --roles read
$ stackit postgresflex user update xxx --instance-id yyy --role login
```

### Options

```
-h, --help Help for "stackit postgresflex user update"
--instance-id string ID of the instance
--roles strings Roles of the user, possible values are ["login" "createdb"] (default [])
--role strings Roles of the user, can be specified multiple times. Possible values are ["login" "createdb"] (default [])
```

### Options inherited from parent commands
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/mongodbflex/user/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
instanceIdFlag = "instance-id"
usernameFlag = "username"
databaseFlag = "database"
rolesFlag = "roles"
roleFlag = "role"
)

var (
Expand Down Expand Up @@ -50,10 +50,10 @@ func NewCmd() *cobra.Command {
Example: examples.Build(
examples.NewExample(
`Create a MongoDB Flex user for instance with ID "xxx" and specify the username`,
"$ stackit mongodbflex user create --instance-id xxx --username johndoe --roles read --database default"),
"$ stackit mongodbflex user create --instance-id xxx --username johndoe --role read --database default"),
examples.NewExample(
`Create a MongoDB Flex user for instance with ID "xxx" with an automatically generated username`,
"$ stackit mongodbflex user create --instance-id xxx --roles read --database default"),
"$ stackit mongodbflex user create --instance-id xxx --role read --database default"),
),
Args: args.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -108,12 +108,12 @@ func NewCmd() *cobra.Command {
}

func configureFlags(cmd *cobra.Command) {
rolesOptions := []string{"read", "readWrite"}
roleOptions := []string{"read", "readWrite"}

cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "ID of the instance")
cmd.Flags().String(usernameFlag, "", "Username of the user. If not specified, a random username will be assigned")
cmd.Flags().String(databaseFlag, "", "The database inside the MongoDB instance that the user has access to. If it does not exist, it will be created once the user writes to it")
cmd.Flags().Var(flags.EnumSliceFlag(false, rolesDefault, rolesOptions...), rolesFlag, fmt.Sprintf("Roles of the user, possible values are %q", rolesOptions))
cmd.Flags().Var(flags.EnumSliceFlag(false, nil, roleOptions...), roleFlag, fmt.Sprintf("Roles of the user, can be specified multiple times. Possible values are %q", roleOptions))

err := flags.MarkFlagsRequired(cmd, instanceIdFlag, databaseFlag)
cobra.CheckErr(err)
Expand All @@ -130,7 +130,7 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) {
InstanceId: flags.FlagToStringValue(cmd, instanceIdFlag),
Username: flags.FlagToStringPointer(cmd, usernameFlag),
Database: flags.FlagToStringPointer(cmd, databaseFlag),
Roles: flags.FlagWithDefaultToStringSlicePointer(cmd, rolesFlag),
Roles: flags.FlagWithDefaultToStringSlicePointer(cmd, roleFlag),
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/mongodbflex/user/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
instanceIdFlag: testInstanceId,
usernameFlag: "johndoe",
databaseFlag: "default",
rolesFlag: "read",
roleFlag: "read",
}
for _, mod := range mods {
mod(flagValues)
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestParseInput(t *testing.T) {
{
description: "roles missing",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, rolesFlag)
delete(flagValues, roleFlag)
}),
isValid: true,
expectedModel: fixtureInputModel(func(model *inputModel) {
Expand All @@ -151,7 +151,7 @@ func TestParseInput(t *testing.T) {
{
description: "invalid role",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[rolesFlag] = "invalid-role"
flagValues[roleFlag] = "invalid-role"
}),
isValid: false,
},
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/mongodbflex/user/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

instanceIdFlag = "instance-id"
databaseFlag = "database"
rolesFlag = "roles"
roleFlag = "role"
)

type inputModel struct {
Expand All @@ -43,7 +43,7 @@ func NewCmd() *cobra.Command {
Example: examples.Build(
examples.NewExample(
`Update the roles of a MongoDB Flex user with ID "xxx" of instance with ID "yyy"`,
"$ stackit mongodbflex user update xxx --instance-id yyy --roles read"),
"$ stackit mongodbflex user update xxx --instance-id yyy --role read"),
),
Args: args.SingleArg(userIdArg, utils.ValidateUUID),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -94,11 +94,11 @@ func NewCmd() *cobra.Command {
}

func configureFlags(cmd *cobra.Command) {
rolesOptions := []string{"read", "readWrite"}
roleOptions := []string{"read", "readWrite"}

cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "ID of the instance")
cmd.Flags().String(databaseFlag, "", "The database inside the MongoDB instance that the user has access to. If it does not exist, it will be created once the user writes to it")
cmd.Flags().Var(flags.EnumSliceFlag(false, nil, rolesOptions...), rolesFlag, fmt.Sprintf("Roles of the user, possible values are %q", rolesOptions))
cmd.Flags().Var(flags.EnumSliceFlag(false, nil, roleOptions...), roleFlag, fmt.Sprintf("Roles of the user, can be specified multiple times. Possible values are %q", roleOptions))

err := flags.MarkFlagsRequired(cmd, instanceIdFlag)
cobra.CheckErr(err)
Expand All @@ -113,7 +113,7 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
}

database := flags.FlagToStringPointer(cmd, databaseFlag)
roles := flags.FlagToStringSlicePointer(cmd, rolesFlag)
roles := flags.FlagToStringSlicePointer(cmd, roleFlag)

if database == nil && roles == nil {
return nil, &errors.EmptyUpdateError{}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/mongodbflex/user/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestParseInput(t *testing.T) {
description: "update roles",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[rolesFlag] = "read"
flagValues[roleFlag] = "read"
}),
isValid: true,
expectedModel: fixtureInputModel(func(model *inputModel) {
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestParseInput(t *testing.T) {
description: "invalid role",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[rolesFlag] = "invalid-role"
flagValues[roleFlag] = "invalid-role"
}),
isValid: false,
},
Expand All @@ -186,7 +186,7 @@ func TestParseInput(t *testing.T) {
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, databaseFlag)
delete(flagValues, rolesFlag)
delete(flagValues, roleFlag)
}),
isValid: false,
},
Expand Down
16 changes: 8 additions & 8 deletions internal/cmd/postgresflex/user/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
const (
instanceIdFlag = "instance-id"
usernameFlag = "username"
rolesFlag = "roles"
roleFlag = "role"
)

var (
Expand All @@ -47,11 +47,11 @@ func NewCmd() *cobra.Command {
),
Example: examples.Build(
examples.NewExample(
`Create a PostgreSQL Flex user for instance with ID "xxx" and specify the username`,
"$ stackit postgresflex user create --instance-id xxx --username johndoe --roles read"),
`Create a PostgreSQL Flex user for instance with ID "xxx"`,
"$ stackit postgresflex user create --instance-id xxx --username johndoe"),
examples.NewExample(
`Create a PostgreSQL Flex user for instance with ID "xxx" with an automatically generated username`,
"$ stackit postgresflex user create --instance-id xxx --roles read"),
`Create a PostgreSQL Flex user for instance with ID "xxx" and permission "createdb"`,
"$ stackit postgresflex user create --instance-id xxx --username johndoe --role createdb"),
),
Args: args.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -105,11 +105,11 @@ func NewCmd() *cobra.Command {
}

func configureFlags(cmd *cobra.Command) {
rolesOptions := []string{"login", "createdb"}
roleOptions := []string{"login", "createdb"}

cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "ID of the instance")
cmd.Flags().String(usernameFlag, "", "Username of the user")
cmd.Flags().Var(flags.EnumSliceFlag(false, rolesDefault, rolesOptions...), rolesFlag, fmt.Sprintf("Roles of the user, possible values are %q", rolesOptions))
cmd.Flags().Var(flags.EnumSliceFlag(false, nil, roleOptions...), roleFlag, fmt.Sprintf("Roles of the user, can be specified multiple times. Possible values are %q", roleOptions))

err := flags.MarkFlagsRequired(cmd, instanceIdFlag, usernameFlag)
cobra.CheckErr(err)
Expand All @@ -125,7 +125,7 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) {
GlobalFlagModel: globalFlags,
InstanceId: flags.FlagToStringValue(cmd, instanceIdFlag),
Username: flags.FlagToStringPointer(cmd, usernameFlag),
Roles: flags.FlagWithDefaultToStringSlicePointer(cmd, rolesFlag),
Roles: flags.FlagWithDefaultToStringSlicePointer(cmd, roleFlag),
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/postgresflex/user/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
projectIdFlag: testProjectId,
instanceIdFlag: testInstanceId,
usernameFlag: "johndoe",
rolesFlag: "login",
roleFlag: "login",
}
for _, mod := range mods {
mod(flagValues)
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestParseInput(t *testing.T) {
{
description: "roles missing",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, rolesFlag)
delete(flagValues, roleFlag)
}),
isValid: true,
expectedModel: fixtureInputModel(func(model *inputModel) {
Expand All @@ -138,7 +138,7 @@ func TestParseInput(t *testing.T) {
{
description: "invalid role",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[rolesFlag] = "invalid-role"
flagValues[roleFlag] = "invalid-role"
}),
isValid: false,
},
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/postgresflex/user/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
userIdArg = "USER_ID"

instanceIdFlag = "instance-id"
rolesFlag = "roles"
roleFlag = "role"
)

type inputModel struct {
Expand All @@ -40,7 +40,7 @@ func NewCmd() *cobra.Command {
Example: examples.Build(
examples.NewExample(
`Update the roles of a PostgreSQL Flex user with ID "xxx" of instance with ID "yyy"`,
"$ stackit postgresflex user update xxx --instance-id yyy --roles read"),
"$ stackit postgresflex user update xxx --instance-id yyy --role login"),
),
Args: args.SingleArg(userIdArg, nil),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -91,10 +91,10 @@ func NewCmd() *cobra.Command {
}

func configureFlags(cmd *cobra.Command) {
rolesOptions := []string{"login", "createdb"}
roleOptions := []string{"login", "createdb"}

cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "ID of the instance")
cmd.Flags().Var(flags.EnumSliceFlag(false, nil, rolesOptions...), rolesFlag, fmt.Sprintf("Roles of the user, possible values are %q", rolesOptions))
cmd.Flags().Var(flags.EnumSliceFlag(false, nil, roleOptions...), roleFlag, fmt.Sprintf("Roles of the user, can be specified multiple times. Possible values are %q", roleOptions))

err := flags.MarkFlagsRequired(cmd, instanceIdFlag)
cobra.CheckErr(err)
Expand All @@ -108,7 +108,7 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
return nil, &errors.ProjectIdError{}
}

roles := flags.FlagToStringSlicePointer(cmd, rolesFlag)
roles := flags.FlagToStringSlicePointer(cmd, roleFlag)
if roles == nil {
return nil, &errors.EmptyUpdateError{}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/postgresflex/user/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
flagValues := map[string]string{
projectIdFlag: testProjectId,
instanceIdFlag: testInstanceId,
rolesFlag: "login",
roleFlag: "login",
}
for _, mod := range mods {
mod(flagValues)
Expand Down Expand Up @@ -149,15 +149,15 @@ func TestParseInput(t *testing.T) {
description: "invalid role",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[rolesFlag] = "invalid-role"
flagValues[roleFlag] = "invalid-role"
}),
isValid: false,
},
{
description: "empty update",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, rolesFlag)
delete(flagValues, roleFlag)
}),
isValid: false,
},
Expand Down

0 comments on commit 72272df

Please sign in to comment.