create.go 1.1 KB

1234567891011121314151617181920212223242526272829
  1. package user
  2. import (
  3. "github.com/gravitl/netmaker/cli/functions"
  4. "github.com/gravitl/netmaker/models"
  5. "github.com/spf13/cobra"
  6. )
  7. var userCreateCmd = &cobra.Command{
  8. Use: "create",
  9. Args: cobra.NoArgs,
  10. Short: "Create a new user",
  11. Long: `Create a new user`,
  12. Run: func(cmd *cobra.Command, args []string) {
  13. user := &models.User{UserName: username, Password: password, IsAdmin: admin}
  14. functions.PrettyPrint(functions.CreateUser(user))
  15. },
  16. }
  17. func init() {
  18. userCreateCmd.Flags().StringVar(&username, "name", "", "Name of the user")
  19. userCreateCmd.Flags().StringVar(&password, "password", "", "Password of the user")
  20. userCreateCmd.MarkFlagRequired("name")
  21. userCreateCmd.MarkFlagRequired("password")
  22. userCreateCmd.Flags().BoolVar(&admin, "admin", false, "Make the user an admin ?")
  23. userCreateCmd.Flags().StringVar(&networks, "networks", "", "List of networks the user will access to (comma separated)")
  24. userCreateCmd.Flags().StringVar(&groups, "groups", "", "List of user groups the user will be part of (comma separated)")
  25. rootCmd.AddCommand(userCreateCmd)
  26. }