package
0.0.0-20240819013456-0d062cb8a7db
Repository: https://github.com/cosys-io/cosys.git
Documentation: pkg.go.dev

# README

cosys_cli - generator

This package contains tools for code generation.

Documentation

Generator

type Generator []Action

Generator is a sequence of actions for code generation.

func (g Generator) Generate() error

Generate performs the sequence of actions.

func NewGenerator(actions ...Action) Generator

NewGenerator returns a new Generator from a sequence of actions.

Action

type Action interface {
	Act() error
}

Action performs a file system change for code generation.

var DeleteIfExists genOption

DeleteIfExists is a configuration for actions, specifying that the given file should be deleted if exists.

var SkipIfExists genOption

SkipIfExists is a configuration for actions, specifying that the action should be skipped if the given file exists.

var GenHeadOnly genOption

GenHeadOnly is a configuration for actions, specifying that only the head of the path should be created.

New Directory Action

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

NewDirAction is an action that creates a new directory.

func (a NewDirAction) Act() error

Act creates a new directory.

func NewDir(path string, options ...genOption) *NewDirAction

NewDir returns a new directory action that creates a new directory at the given path.

New File Action

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

NewFileAction is an action that create a new file.

func (a NewFileAction) Act() error

Act creates a new file.

func NewFile(path string, tmplString string, ctx any, options ...genOption) *NewFileAction

NewFile returns a new file action that creates a file at the given path using the given template and context.

Modify File Action

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

ModifyFileAction is an action that modifies a file.

func (a ModifyFileAction) Act() error

Act modifies a file.

func ModifyFile(path, patternString, tmplString string, ctx any) *ModifyFileAction

ModifyFile returns a modify file action that modifies the file at the given path, replacing all text matching the given regex pattern with the given template and context.

# Functions

ModifyFile returns a modify file action that modifies the file at the given path, replacing all text matching the given regex pattern with the given template and context.
NewDir returns a new directory action that creates a new directory at the given path.
NewFile returns a new file action that creates a file at the given path using the given template and context.
NewGenerator returns a new Generator from a sequence of actions.

# Variables

DeleteIfExists is a configuration for actions, specifying that the given file should be deleted if exists.
GenHeadOnly is a configuration for actions, specifying that only the head of the path should be created.
SkipIfExists is a configuration for actions, specifying that the action should be skipped if the given file exists.

# Structs

ModifyFileAction is an action that modifies a file.
NewDirAction is an action that creates a new directory.
NewFileAction is an action that create a new file.

# Interfaces

Action performs a file system change for code generation.

# Type aliases

Generator is a sequence of actions for code generation.