config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Track generate comment, which is used to mark the generate of the track
	TrackGenerateComment = "// +goat:generate"
	// Track tips comment, which is used to mark the tips of the track
	TrackTipsComment = "// +goat:tips: do not edit the block between the +goat comments"
	// Track delete comment, which is used to mark the delete of the track
	// goat fix will try to delete codes
	TrackDeleteComment = "// +goat:delete"
	// Track import comment, which is used to mark the import of the track
	TrackImportComment = "// +goat:import"
	// Track insert comment, which is used to mark to add by human
	// goat fix will try to insert codes the goat fix will try to insert codes the goat fix will try to insert codes the
	TrackInsertComment = "// +goat:insert"
	// Track main entry comment, which is used to mark the main entry of the track
	TrackMainEntryComment = "// +goat:main"
	// Track end comment, which is used to mark the end of the track
	TrackEndComment = "// +goat:end"
	// Track user comment, which is used to mark the track is user defined
	TrackUserComment = "// +goat:user"
)
View Source
const (
	GranularityLineStr  = "line"
	GranularityPatchStr = "patch"
	GranularityScopeStr = "scope"
	GranularityFuncStr  = "func"
)
View Source
const CONFIG_TEMPLATE = `` /* 3321-byte string literal not displayed */

Variables

View Source
var (
	// Track insert regexp, which is used to match the insert comment
	TrackInsertRegexp = regexp.MustCompile(`(?m)^\s*` + regexp.QuoteMeta(TrackInsertComment) + `[^\n]*\n`)
	// Track generate end regexp, which is used to match the generate end comment
	TrackGenerateEndRegexp = regexp.MustCompile(`(?m)^\s*` + regexp.QuoteMeta(TrackGenerateComment) +
		`[^\n]` + `*\n(?:.*\n)*?\s*` + regexp.QuoteMeta(TrackEndComment) + `[^\n]*\n`)
	// Track delete end regexp, which is used to match the delete end comment
	TrackDeleteEndRegexp = regexp.MustCompile(`(?m)^\s*` + regexp.QuoteMeta(TrackDeleteComment) +
		`[^\n]` + `*\n(?:.*\n)*?\s*` + regexp.QuoteMeta(TrackEndComment) + `[^\n]*\n`)
	// Track main entry end regexp, which is used to match the main entry end comment
	TrackMainEntryEndRegexp = regexp.MustCompile(`(?m)^\s*` + regexp.QuoteMeta(TrackMainEntryComment) +
		`[^\n]` + `*\n(?:.*\n)*?\s*` + regexp.QuoteMeta(TrackEndComment) + `[^\n]*\n`)
	// Track user end regexp, which is used to match the user end comment
	TrackUserEndRegexp = regexp.MustCompile(`(?m)^\s*` + regexp.QuoteMeta(TrackUserComment) +
		`[^\n]` + `*\n(?:.*\n)*?\s*` + regexp.QuoteMeta(TrackEndComment) + `[^\n]*\n`)
)
View Source
var ConfigYaml string

Functions

func GoModuleName

func GoModuleName() string

GetGoModuleName gets the module name from the go.mod file

func InitWithConfig

func InitWithConfig(filename string, cfg *Config) error

InitWithConfig initializes configuration with a Config struct

Types

type Config

type Config struct {
	// App name
	AppName string `yaml:"appName"` // goat
	// App version
	AppVersion string `yaml:"appVersion"` // 1.0.0
	// Old branch name
	OldBranch string `yaml:"oldBranch"` // valid values: [commit hash, branch name, tag name, "", HEAD, INIT (for new repository)]
	// New branch name
	NewBranch string `yaml:"newBranch"` // valid values: [commit hash, branch name, tag name, "", HEAD]
	// Files or directories to ignore
	Ignores []string `yaml:"ignores"`
	// Goat package name
	GoatPackageName string `yaml:"goatPackageName"`
	// Goat package alias
	GoatPackageAlias string `yaml:"goatPackageAlias"`
	// Goat package path
	GoatPackagePath string `yaml:"goatPackagePath"`
	// Granularity
	Granularity string `yaml:"granularity"` // line, block, scope, func
	// Diff precision
	DiffPrecision int `yaml:"diffPrecision"` // valid values: 1~3
	// Threads
	Threads int `yaml:"threads"` // 1~128
	// Race
	Race bool `yaml:"race"` // true, false
	// Main packages to track
	MainEntries []string `yaml:"mainEntries"`
	// Printer config
	// PrinterConfigMode is the mode of the printer config
	// default  useSpaces | tabIndent
	PrinterConfigMode []PrinterConfigMode `yaml:"printerConfigMode"` // default: useSpaces | tabIndent
	// PrinterConfigTabwidth is the tab width of the printer config
	PrinterConfigTabwidth int `yaml:"printerConfigTabwidth"` // default: 8
	// PrinterConfigIndent is the indent of the printer config
	PrinterConfigIndent int `yaml:"printerConfigIndent"` // default: 0

	// Data type
	DataType string `yaml:"dataType"` // default: truth
	// Verbose output
	Verbose bool `yaml:"verbose"` // default: false
	// contains filtered or unexported fields
}

Config configuration struct

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig loads configuration from file

func (*Config) GetDataType

func (c *Config) GetDataType() DataType

func (*Config) GetGranularity

func (c *Config) GetGranularity() Granularity

GetGranularity returns the granularity

func (*Config) GoatGeneratedFile

func (c *Config) GoatGeneratedFile() string

GoatGeneratedFile returns the goat generated file path

func (*Config) IsMainEntry

func (c *Config) IsMainEntry(entry string) bool

IsMainEntry checks if the entry is a main entry

func (*Config) IsNewRepository

func (c *Config) IsNewRepository() bool

IsNewRepository returns true if the old branch is "INIT"

func (*Config) PrinterConfig

func (c *Config) PrinterConfig() *printer.Config

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the config

type DataType

type DataType int

DataType is the type of the data

const (

	// DataTypeTruth is the truth type
	DataTypeTruth DataType // default
	// DataTypeCount is the count type
	DataTypeCount
)

DataTypeTruth is the truth type

func GetDataType

func GetDataType(s string) (DataType, error)

func (DataType) Int

func (d DataType) Int() int

Int returns the integer representation of the data type

func (DataType) IsValid

func (d DataType) IsValid() bool

IsValid checks if the data type is valid

func (DataType) String

func (d DataType) String() string

String returns the string representation of the data type

type Granularity

type Granularity int
const (

	// GranularityLine is the line granularity
	GranularityLine Granularity
	// GranularityPatch is the patch(diff patch in the same scope) granularity
	GranularityPatch
	// GranularityScope is the scope granularity
	GranularityScope
	// GranularityFunc is the func granularity
	GranularityFunc
)

GranularityLine is the line granularity

func ToGranularity

func ToGranularity(s string) (Granularity, error)

ToGranularity converts a string to a granularity

func (Granularity) Int

func (g Granularity) Int() int

Int returns the integer representation of the granularity

func (Granularity) IsFunc

func (g Granularity) IsFunc() bool

IsFunc checks if the granularity is func

func (Granularity) IsLine

func (g Granularity) IsLine() bool

IsLine checks if the granularity is line

func (Granularity) IsPatch

func (g Granularity) IsPatch() bool

IsPatch checks if the granularity is block

func (Granularity) IsScope

func (g Granularity) IsScope() bool

IsScope checks if the granularity is scope

func (Granularity) IsValid

func (g Granularity) IsValid() bool

IsValid checks if the granularity is valid

func (Granularity) String

func (g Granularity) String() string

String returns the string representation of the granularity

type PrinterConfigMode

type PrinterConfigMode string

PrinterConfigMode is the mode of the printer config

const (
	PrinterConfigModeNone PrinterConfigMode = ""
	// same as printer.UseSpaces
	PrinterConfigModeUseSpaces PrinterConfigMode = "useSpaces"
	// same as printer.TabIndent
	PrinterConfigModeTabIndent PrinterConfigMode = "tabIndent"
	// same as printer.SourcePos
	PrinterConfigModeSourcePos PrinterConfigMode = "sourcePos"
	// same as printer.RawFormat
	PrinterConfigModeRawFormat PrinterConfigMode = "rawFormat"
)

PrinterConfigModeNone is the none mode of the printer config default useSpaces | tabIndent

func (PrinterConfigMode) IsValid

func (p PrinterConfigMode) IsValid() bool

IsValid checks if the printer config mode is valid

func (PrinterConfigMode) Mode

func (p PrinterConfigMode) Mode() printer.Mode

Mode returns the printer mode

Jump to

Keyboard shortcuts

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