cli

package module
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 27 Imported by: 1

README

Lemmego CLI

Lemmego CLI is used for generating the framework components.

Installation

For Linux & macOS Users
curl -fsSL https://raw.githubusercontent.com/lemmego/cli/refs/heads/main/installer.sh | sudo sh

Usage

Create a new project:

lemmego new <your-module-name>

A new project will be created in your current directory (must be an empty dir)

Generate a handlers file:

lemmego g handlers post

A post_handlers.go file will be generated in your project under the ./internal/handlers directory.

Generate a model file:

lemmego g model post

A post.go file will be generated in your project under the ./internal/models directory.

Generate a form file:

lemmego g form post

A Form.tsx file will be generated in your project under the ./resources/js/Pages/Forms directory.

Generate a HTTP request input file:

lemmego g input post

A post_input.go file will be generated in your project under the ./internal/inputs directory.

Generate a migration file:

lemmego g migration create_users_table

A _create_users_table.go file will be generated in your project under the ./internal/migrations directory (if you haven't overridden the default MIGRATIONS_DIR env value).

All these commands also take an interactive flag (-i), where additional configuration option is provided:

lemmego g -i handlers
lemmego g -i model
lemmego g -i form
lemmego g -i input
lemmego g -i migration

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Documentation

Index

Constants

View Source
const (
	RelationOneToOne   = "one_to_one"
	RelationOneToMany  = "one_to_many"
	RelationManyToOne  = "many_to_one"
	RelationManyToMany = "many_to_many"
)

Variables

View Source
var CommonModelFields = []*ModelField{
	{
		Name:     "id",
		Type:     "uint64",
		Required: true,
		Primary:  true,
	},
	{
		Name:     "created_at",
		Type:     "time.Time",
		Required: true,
	},
	{
		Name:     "updated_at",
		Type:     "time.Time",
		Required: true,
	},
	{
		Name:     "deleted_at",
		Type:     "time.Time",
		Required: true,
	},
}
View Source
var In = func(allowList []string, message string, validators ...ValidateFunc) ValidateFunc {
	return func(input string) error {
		if slices.Contains(allowList, strings.ToLower(input)) {
			if message == "" {
				return errors.New(fmt.Sprintf("input must contain %s", strings.Join(allowList, ",")))
			}
			return errors.New(message)
		}
		for _, v := range validators {
			if err := v(input); err != nil {
				return err
			}
		}
		return nil
	}
}
View Source
var NotIn = func(ignoreList []string, message string, validators ...ValidateFunc) ValidateFunc {
	return func(input string) error {
		if slices.Contains(ignoreList, strings.ToLower(input)) {
			if message == "" {
				return errors.New(fmt.Sprintf("input must not contain %s", strings.Join(ignoreList, ",")))
			}
			return errors.New(message)
		}
		for _, v := range validators {
			if err := v(input); err != nil {
				return err
			}
		}
		return nil
	}
}
View Source
var SnakeCase = func(input string) error {
	if len(input) == 0 {
		return errors.New("input cannot be empty")
	}

	if len(input) > 0 && input[0] < 'a' || input[0] > 'z' {
		return errors.New("field name must start with a lowercase letter")
	}

	for _, c := range input {
		if c < 'a' || c > 'z' {
			if c < '0' || c > '9' {
				if c != '_' {
					return errors.New("field name must contain only lowercase letters, numbers, and underscores")
				}
			}
		}
	}
	return nil
}
View Source
var SnakeCaseEmptyAllowed = func(input string) error {
	if len(input) == 0 {
		return nil
	}

	if len(input) > 0 && input[0] < 'a' || input[0] > 'z' {
		return errors.New("field name must start with a lowercase letter")
	}

	for _, c := range input {
		if c < 'a' || c > 'z' {
			if c < '0' || c > '9' {
				if c != '_' {
					return errors.New("field name must contain only lowercase letters, numbers, and underscores")
				}
			}
		}
	}
	return nil
}
View Source
var UiDataTypeMap = map[string]string{
	"text":     reflect.String.String(),
	"textarea": reflect.String.String(),
	"integer":  reflect.Uint.String(),
	"decimal":  reflect.Float64.String(),
	"boolean":  reflect.Bool.String(),
	"radio":    reflect.String.String(),
	"checkbox": reflect.String.String(),
	"dropdown": reflect.String.String(),
	"date":     "time.Time",
	"time":     "time.Time",
	"file":     reflect.String.String(),
}
View Source
var UiDbTypeMap = map[string]string{
	"text":     "string",
	"textarea": "text",
	"integer":  "unsignedBigInt",
	"decimal":  "decimal",
	"boolean":  "boolean",
	"radio":    "string",
	"checkbox": "string",
	"dropdown": "string",
	"date":     "dateTime",
	"time":     "time",
	"file":     "string",
}

Functions

func AddCmd

func AddCmd(cmd *cobra.Command)

AddCmd adds a new sub-command to the root command.

func CopyDir added in v0.1.10

func CopyDir(src string, dst string) error

CopyDir copies the src dir to dst

func CopyFile added in v0.1.10

func CopyFile(src, dst string) error

CopyFile is a helper function to copy a file

func CreateDirIfNotExists added in v0.1.10

func CreateDirIfNotExists(dirPath string)

CreateDirIfNotExists creates a directory if it does not exist

func DirPath added in v0.1.10

func DirPath(dirname string) string

DirPath returns the full directory path for a directory name

func EnsureBinary added in v0.1.10

func EnsureBinary(binary string)

EnsureBinary ensures the git binary is present in the system

func EnsureEmptyDir added in v0.1.10

func EnsureEmptyDir(dirname string)

EnsureEmptyDir ensures the directory in which the project should be created is empty

func Execute

func Execute() error

Execute the command and register the sub-commands.

func HasBinary added in v0.1.10

func HasBinary(binary string) bool

HasBinary returns if the given binary is installed in the system

func HasDirectory added in v0.1.10

func HasDirectory(dirPath string) bool

HasDirectory returns true if a directory exists and false otherwise

func ParseTemplate

func ParseTemplate(tmplData map[string]interface{}, fileContents string, funcMap template.FuncMap) (string, error)

func RemoveDirs added in v0.1.10

func RemoveDirs(dirPath string, dirNames []string)

RemoveDirs removes the list of given directories

func RunCommand added in v0.1.10

func RunCommand(dirPath string, command string, args ...string)

RunCommand runs a command in a specific directory

func ScanStr added in v0.1.10

func ScanStr(input *string, label string)

ScanStr scans the given input

Types

type CommandGenerator

type CommandGenerator interface {
	Generator
	PackagePathGetter
	StubGetter
	Commander
}

type Commander

type Commander interface {
	Command() *cobra.Command
}

type DBTag

type DBTag struct {
	Name     string
	Argument string
}

type DBTagBuilder

type DBTagBuilder struct {
	// contains filtered or unexported fields
}

func NewDBTagBuilder

func NewDBTagBuilder(tags []*DBTag, driverName string) *DBTagBuilder

func (*DBTagBuilder) Add

func (mtb *DBTagBuilder) Add(name, argument string) *DBTagBuilder

func (*DBTagBuilder) Build

func (mtb *DBTagBuilder) Build() string

type FormConfig

type FormConfig struct {
	Name   string
	Flavor string // templ, react
	Fields []*FormField
	Route  string
}

type FormField

type FormField struct {
	Name    string
	Type    string
	Choices []string
}

type FormGenerator

type FormGenerator struct {
	// contains filtered or unexported fields
}

func NewFormGenerator

func NewFormGenerator(mc *FormConfig) *FormGenerator

func (*FormGenerator) Generate

func (fg *FormGenerator) Generate(appendable ...[]byte) error

func (*FormGenerator) GetPackagePath

func (fg *FormGenerator) GetPackagePath() string

func (*FormGenerator) GetReplacables

func (fg *FormGenerator) GetReplacables() []*Replacable

func (*FormGenerator) GetStub

func (fg *FormGenerator) GetStub() string

type Gen

type Gen struct {
	Name       string
	Appendable []byte
}

type Generator

type Generator interface {
	Generate() error
}

type HandlerConfig

type HandlerConfig struct {
	Name string
}

type HandlerField

type HandlerField struct {
	Name string
}

type HandlerGenerator

type HandlerGenerator struct {
	// contains filtered or unexported fields
}

func NewHandlerGenerator

func NewHandlerGenerator(mc *HandlerConfig) *HandlerGenerator

func (*HandlerGenerator) Command

func (hg *HandlerGenerator) Command() *cobra.Command

func (*HandlerGenerator) Generate

func (hg *HandlerGenerator) Generate(appendable ...[]byte) error

func (*HandlerGenerator) GetPackagePath

func (hg *HandlerGenerator) GetPackagePath() string

func (*HandlerGenerator) GetStub

func (hg *HandlerGenerator) GetStub() string

type InputConfig

type InputConfig struct {
	Name   string
	Fields []*InputField
}

type InputField

type InputField struct {
	Name         string
	Type         string
	Required     bool
	Unique       bool
	Table        string
	WhereClauses []map[string]interface{}
}

type InputGenerator

type InputGenerator struct {
	// contains filtered or unexported fields
}

func NewInputGenerator

func NewInputGenerator(mc *InputConfig) *InputGenerator

func (*InputGenerator) Command

func (ig *InputGenerator) Command() *cobra.Command

func (*InputGenerator) Generate

func (ig *InputGenerator) Generate(appendable ...[]byte) error

func (*InputGenerator) GetPackagePath

func (ig *InputGenerator) GetPackagePath() string

func (*InputGenerator) GetStub

func (ig *InputGenerator) GetStub() string

type MigrationConfig

type MigrationConfig struct {
	TableName      string
	Fields         []*MigrationField
	PrimaryColumns []string
	UniqueColumns  [][]string
	ForeignColumns [][]string
	Timestamps     bool
}

type MigrationField

type MigrationField struct {
	Name               string
	Type               string
	Nullable           bool
	Unique             bool
	Primary            bool
	ForeignConstrained bool
}

type MigrationGenerator

type MigrationGenerator struct {
	Timestamps bool
	// contains filtered or unexported fields
}

func NewMigrationGenerator

func NewMigrationGenerator(mc *MigrationConfig) *MigrationGenerator

func (*MigrationGenerator) BumpVersion

func (mg *MigrationGenerator) BumpVersion() *MigrationGenerator

func (*MigrationGenerator) Command

func (mg *MigrationGenerator) Command() *cobra.Command

func (*MigrationGenerator) Generate

func (mg *MigrationGenerator) Generate(appendable ...[]byte) error

func (*MigrationGenerator) GetPackagePath

func (mg *MigrationGenerator) GetPackagePath() string

func (*MigrationGenerator) GetStub

func (mg *MigrationGenerator) GetStub() string

type ModelConfig

type ModelConfig struct {
	Name   string
	Fields []*ModelField
}

type ModelField

type ModelField struct {
	Name               string
	Type               string
	Required           bool
	Unique             bool
	Primary            bool
	ForeignConstrained bool
	Relation           string
}

type ModelGenerator

type ModelGenerator struct {
	// contains filtered or unexported fields
}

func NewModelGenerator

func NewModelGenerator(mc *ModelConfig) *ModelGenerator

func (*ModelGenerator) Command

func (mg *ModelGenerator) Command() *cobra.Command

func (*ModelGenerator) Generate

func (mg *ModelGenerator) Generate(appendable ...[]byte) error

func (*ModelGenerator) GetPackagePath

func (mg *ModelGenerator) GetPackagePath() string

func (*ModelGenerator) GetStub

func (mg *ModelGenerator) GetStub() string

type PackagePathGetter

type PackagePathGetter interface {
	GetPackagePath() string
}

type Replacable

type Replacable struct {
	Placeholder string
	Value       interface{}
}

type RepoConfig added in v0.1.13

type RepoConfig struct {
	Name string
}

type RepoGenerator added in v0.1.13

type RepoGenerator struct {
	// contains filtered or unexported fields
}

func NewRepoGenerator added in v0.1.13

func NewRepoGenerator(rc *RepoConfig) *RepoGenerator

func (*RepoGenerator) Command added in v0.1.13

func (rg *RepoGenerator) Command() *cobra.Command

func (*RepoGenerator) Generate added in v0.1.13

func (rg *RepoGenerator) Generate(appendable ...[]byte) error

func (*RepoGenerator) GetPackagePath added in v0.1.13

func (rg *RepoGenerator) GetPackagePath() string

func (*RepoGenerator) GetStub added in v0.1.13

func (rg *RepoGenerator) GetStub() string

type StubGetter

type StubGetter interface {
	GetStub() string
}

type Tag added in v0.1.10

type Tag struct {
	Name   string `json:"name"`
	Commit struct {
		Sha string `json:"sha"`
	} `json:"commit"`
}

type ValidateFunc

type ValidateFunc func(string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL