update.go 1018 B

1234567891011121314151617181920212223242526272829303132333435
  1. package user
  2. import (
  3. "strings"
  4. "github.com/gravitl/netmaker/cli/functions"
  5. "github.com/gravitl/netmaker/models"
  6. "github.com/spf13/cobra"
  7. )
  8. var userUpdateCmd = &cobra.Command{
  9. Use: "update [USER NAME]",
  10. Args: cobra.ExactArgs(1),
  11. Short: "Update a user",
  12. Long: `Update a user`,
  13. Run: func(cmd *cobra.Command, args []string) {
  14. user := &models.User{UserName: args[0], IsAdmin: admin}
  15. if networks != "" {
  16. user.Networks = strings.Split(networks, ",")
  17. }
  18. if groups != "" {
  19. user.Groups = strings.Split(groups, ",")
  20. } else {
  21. user.Groups = []string{"*"}
  22. }
  23. functions.PrettyPrint(functions.UpdateUser(user))
  24. },
  25. }
  26. func init() {
  27. userUpdateCmd.Flags().BoolVar(&admin, "admin", false, "Make the user an admin ?")
  28. userUpdateCmd.Flags().StringVar(&networks, "networks", "", "List of networks the user will access to (comma separated)")
  29. userUpdateCmd.Flags().StringVar(&groups, "groups", "", "List of user groups the user will be part of (comma separated)")
  30. rootCmd.AddCommand(userUpdateCmd)
  31. }