Documentation
¶
Index ¶
- Constants
- Variables
- func GoModuleName() string
- func InitWithConfig(filename string, cfg *Config) error
- type Config
- func (c *Config) GetDataType() DataType
- func (c *Config) GetGranularity() Granularity
- func (c *Config) GoatGeneratedFile() string
- func (c *Config) IsMainEntry(entry string) bool
- func (c *Config) IsNewRepository() bool
- func (c *Config) PrinterConfig() *printer.Config
- func (c *Config) Validate() error
- type DataType
- type Granularity
- type PrinterConfigMode
Constants ¶
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" )
const ( GranularityLineStr = "line" GranularityPatchStr = "patch" GranularityScopeStr = "scope" GranularityFuncStr = "func" )
const CONFIG_TEMPLATE = `` /* 3321-byte string literal not displayed */
Variables ¶
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`) )
var ConfigYaml string
Functions ¶
func GoModuleName ¶
func GoModuleName() string
GetGoModuleName gets the module name from the go.mod file
func InitWithConfig ¶
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 ¶
LoadConfig loads configuration from file
func (*Config) GetDataType ¶
func (*Config) GetGranularity ¶
func (c *Config) GetGranularity() Granularity
GetGranularity returns the granularity
func (*Config) GoatGeneratedFile ¶
GoatGeneratedFile returns the goat generated file path
func (*Config) IsMainEntry ¶
IsMainEntry checks if the entry is a main entry
func (*Config) IsNewRepository ¶
IsNewRepository returns true if the old branch is "INIT"
func (*Config) PrinterConfig ¶
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 ¶
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