๐Ÿ› ๏ธ CreateAdmin โ€“ CLI Tool to Seed an Admin User

The CreateAdmin CLI command creates a new admin user in the database. It's used to bootstrap the first superuser for your system, often run once during setup or testing.


โš™๏ธ Command-Line Usage

go run main.go --name="Alice Admin" --email="[email protected]" --password="securepass123"

All flags are required. If any are missing, the tool exits with an error.


๐Ÿงฑ Main Logic

main

func main()

Entry point that parses flags, validates input, connects to the DB, hashes the password, and inserts the admin user.


๐Ÿงพ Input Flags

Flag Type Description
--name string Full name of the admin
--email string Email address (must be unique)
--password string Plaintext password (will be hashed)

๐Ÿง  Flow & Logic

  1. Parse CLI Flags

    Uses the Go flag package to get user input.

  2. Validate Required Input

    Exits with log.Fatal if any flag is missing.

  3. Load Configuration

    Loads environment variables using config.LoadConfig(".").

  4. Initialize DB Connection

    Creates a PostgreSQL connection pool using pgxpool.New.