Skip to content

base-go/cmd

Repository files navigation

Base - Command Line Tool for the Base Framework

Base is a powerful command-line tool designed to streamline development with the Base framework. It offers scaffolding, module generation, and utilities to accelerate Go application development.

Installation

macOS and Linux

curl -fsSL https://get.base.al | bash

If you need to install in a protected directory (like /usr/local/bin), use:

curl -fsSL https://get.base.al | sudo bash

Windows

Option 1: Using PowerShell (Recommended)

  1. Open PowerShell as Administrator
  2. Run:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/base-go/cmd/main/install.ps1'))

Option 2: Using Git Bash

curl -fsSL https://get.base.al | bash

Commands

base new <project-name>

Create a new project using the Base framework.

base new myapp

base generate or base g

Generate a new module with fields and relationships.

base g <module-name> [field:type ...] [options]

base start or base s

Start the Base application server.

Options:

  • --docs, -d: Generate Swagger documentation

Examples:

# Start the server normally
base start

# Start with Swagger documentation
base s -d

base docs

Generate OpenAPI 3.0 documentation using swag by scanning controller annotations and create static files.

base docs [flags]

Options:

  • -o, --output string: Output directory for generated files (default "docs")

Examples:

# Generate docs in default 'docs' directory
base docs

# Generate docs in custom directory
base docs --output api-docs

Generated files:

  • swagger.json: OpenAPI 3.0 specification in JSON format
  • swagger.yaml: OpenAPI 3.0 specification in YAML format
  • docs.go: Go package with embedded OpenAPI spec for programmatic access
  • index.html: Lightweight Swagger UI served from CDN

Notes:

  • Documentation is served at /docs/ when running the server
  • You can also run base start -d to auto-generate docs before starting the server
  • All swagger info (title, version, description) is extracted from main.go annotations
  • Uses swag for modern OpenAPI 3.0 support with better performance

base scheduler or base sc

Manage scheduled tasks in your Base Framework application.

Subcommands:

  • generate, g: Generate a new scheduled task
  • list, ls: List all registered tasks
  • run: Run a specific task immediately
  • enable: Enable a specific task
  • disable: Disable a specific task
  • status: Get scheduler status

Options:

  • --api-key: API key for authentication
  • --url: Base URL of the application (default: http://localhost:8100)

Examples:

# Generate a new task (smart module detection)
base scheduler generate posts cleanup-old-posts
base scheduler g users send-weekly-digest
base scheduler g Post publish    # Finds 'posts' module
base scheduler g User reminder   # Finds 'users' module

# List all tasks (requires API key)
base scheduler list --api-key=your-key

# Run a task immediately
base scheduler run cleanup-old-posts --api-key=your-key

# Enable/disable tasks
base scheduler enable cleanup-old-posts --api-key=your-key
base scheduler disable cleanup-old-posts --api-key=your-key

# Get scheduler status
base scheduler status --api-key=your-key

# Alternative short commands
base sched g posts cleanup
base sched list --api-key=your-key

base d or base destroy

Destroy (delete) one or more existing modules.

base d [name1] [name2] ... [flags]

Examples:

# Destroy a single module
base d user

# Destroy multiple modules at once
base d user customer order

# Alternative command name
base destroy user customer

What gets removed:

  • Module directory (app/modulename/)
  • Model file (app/models/modulename.go)
  • Import and registration from app/init.go

Notes:

  • Requires confirmation before destroying modules
  • Will attempt to clean up orphaned entries even if module directory doesn't exist
  • Shows progress for each module when destroying multiple modules

base update

Update framework core components:

base update

base upgrade

Upgrade the Base CLI tool:

base upgrade

base version

Display version information:

base version

Field Types

Base supports various field types for model generation:

Basic Types:

  • string
  • bool
  • int, uint (also int8, int16, int32, int64, uint8, uint16, uint32, uint64)
  • float, float32, float64
  • text (stored as string with appropriate DB type)

Special Types and Aliases (mapping shown on the right):

  • email, url, slug → string
  • datetime, time, datetypes.DateTime
  • decimal, floatfloat64
  • sortint
  • translation, translatedFieldtranslation.Field
  • image, file, attachment*storage.Attachment

Notes:

  • Attachment fields are handled via dedicated upload endpoints and are not included in JSON create/update payloads.
  • Email/URL/Slug are strings; GORM tags may add size/indexing automatically.
  • Datetime types use Base types.DateTime under the hood.

Relationship Types (both snake_case and camelCase accepted):

  • belongs_to (or belongsTo): one-to-one with FK on this model
  • has_one (or hasOne): one-to-one with FK on the other model
  • has_many (or hasMany): one-to-many
  • to_many (or toMany): many-to-many with join table

Relationship auto-detection:

  • Defining a field as <name>_id:uint will also generate the corresponding belongs_to relationship for <name> automatically.

Type inference (when no explicit type is given):

  • <name>_iduint (FK)
  • Contains one of: description, content, body, notes, comment, summary, bio, abouttext
  • Prefix or contains: is_, has_, can_, enabled, active, published, verified, confirmedbool
  • Contains: price, amountdecimal; other numeric-like names (count, quantity, number, rating, score, weight, height, width) → int
  • Suffix _at, _on, _date or contains common datetime terms (date, time, created_at, updated_at, deleted_at, published_at, expires_at) → datetime
  • Contains emailemail (string)
  • Contains url or linkurl (string)
  • Contains image, photo, picture, avatarimage (attachment)
  • Contains file, document, attachmentfile (attachment)
  • Contains translation, i18n, localetranslatedField
  • Otherwise → string

Example:

# Generate a post module with title and image
base g post title:string cover:image

# Generate a document module with title and file attachment
base g document title:string file:file

Example: Building a Blog System

Here's a comprehensive example of building a blog system with categories, posts, tags, and comments:

# Generate Category model
base g Category \
  name:string \
  description:text \
  image:attachment \
  parent:belongsTo:Category \
  posts:hasMany:Post

# Generate Post model
base g Post \
  title:string \
  content:text \
  excerpt:text \
  featured_image:attachment \
  gallery:attachment \
  published_at:datetime \
  author:belongsTo:users.User \
  category:belongsTo:Category \
  comments:hasMany:Comment \
  tags:toMany:Tag

# Generate Tag model
base g Tag \
  name:string \
  slug:string 
 

# Generate Comment model
base g Comment \
  content:text \
  author:belongsTo:users.User \
  post:belongsTo:Post

This will create:

  • Full CRUD operations for all models
  • RESTful API endpoints with Swagger documentation
  • File upload handling for images
  • Proper relationships and preloading
  • Authentication and authorization integration

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Base CMD

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •