Skip to content

Commit

Permalink
Completion mysql-user option in kubectl-moco mysql
Browse files Browse the repository at this point in the history
Signed-off-by: Masayuki Ishii <[email protected]>
  • Loading branch information
masa213f committed Nov 2, 2022
1 parent 416990f commit 88f4aa8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cmd/kubectl-moco/cmd/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/cybozu-go/moco/pkg/constants"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -47,11 +48,11 @@ password="%s"

func init() {
fs := credentialCmd.Flags()
fs.StringVarP(&credentialConfig.user, "mysql-user", "u", "moco-readonly", "User for login to mysql")
fs.StringVarP(&credentialConfig.user, "mysql-user", "u", constants.ReadOnlyUser, "User for login to mysql")
fs.StringVar(&credentialConfig.format, "format", "plain", "The format of output [`plain` or `mycnf`]")

_ = credentialCmd.RegisterFlagCompletionFunc("mysql-user", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"moco-readonly", "moco-writable", "moco-admin"}, cobra.ShellCompDirectiveDefault
return []string{constants.ReadOnlyUser, constants.WritableUser, constants.AdminUser}, cobra.ShellCompDirectiveDefault
})
_ = credentialCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"plain", "mycnf"}, cobra.ShellCompDirectiveDefault
Expand Down
6 changes: 5 additions & 1 deletion cmd/kubectl-moco/cmd/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ func runMySQLCommand(ctx context.Context, clusterName string, cmd *cobra.Command

func init() {
fs := mysqlCmd.Flags()
fs.StringVarP(&mysqlConfig.user, "mysql-user", "u", "moco-readonly", "User for login to mysql")
fs.StringVarP(&mysqlConfig.user, "mysql-user", "u", constants.ReadOnlyUser, "User for login to mysql")
fs.IntVar(&mysqlConfig.index, "index", -1, "Index of the target mysql instance")
fs.BoolVarP(&mysqlConfig.stdin, "stdin", "i", false, "Pass stdin to the mysql container")
fs.BoolVarP(&mysqlConfig.tty, "tty", "t", false, "Allocate a TTY to stdin")

_ = mysqlCmd.RegisterFlagCompletionFunc("mysql-user", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{constants.ReadOnlyUser, constants.WritableUser, constants.AdminUser}, cobra.ShellCompDirectiveDefault
})

rootCmd.AddCommand(mysqlCmd)
}

0 comments on commit 88f4aa8

Please sign in to comment.