internal

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsoleRed added in v0.1.3

func ConsoleRed(txt string) string

ConsoleRed 控制台红色字符

func Execute

func Execute(args []string)

Types

type Command added in v0.1.3

type Command struct {
	// Match 用于匹配执行命令的正则表达式,可选
	// 如命令为 "git add ." 则,"add ." 会交给此正则来匹配
	// 若不匹配,当前这组命令将不会执行
	Match string `json:",omitempty"`

	// Cond 额外的执行条件,可选
	// 如:
	// go_module: 当前命令在 go module 里,即当前目录或者上级目录有 go.mod 文件
	// exec xx.sh : 执行 xx.sh 并执行成功
	// has_file app.toml: 当前目录或者上级目录有 app.toml 文件
	Cond []Condition `json:",omitempty"`

	// Cmd 命令,必填
	Cmd string

	Args []string `json:",omitempty"`

	// Timeout 超时时间,默认 1 分钟
	Timeout time.Duration `json:",omitempty"`

	Trace bool `json:",omitempty"`

	// AllowFail 是否允许执行失败,默认否
	// 默认情况下,当此命令执行失败后,后续命令也不会执行,程序将退出
	AllowFail bool `json:",omitempty"`

	// Env 执行此命令所特有的环境变量信息
	Env []string `json:",omitempty"`
}

func (*Command) CanRun added in v0.1.4

func (c *Command) CanRun() bool

func (*Command) Exec added in v0.1.3

func (c *Command) Exec(ctx context.Context, env []string)

Exec 执行命令 env 变量已经包含了 os.Environ()

func (*Command) IsMatch added in v0.1.3

func (c *Command) IsMatch(str string) (bool, error)

type Condition added in v0.1.4

type Condition string

func (Condition) Allow added in v0.1.4

func (c Condition) Allow() bool

type Config

type Config struct {
	Rules []*Rule

	// Trace 是否调试模式,默认 true
	// 目前只控制是否打印过程日志
	Trace bool

	// Spec 不同命令,特殊的配置
	// 每种命令的配置都不同,详见 spec.go
	Spec map[string]any
	// contains filtered or unexported fields
}

func LoadConfig

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

func (*Config) Format added in v0.1.1

func (c *Config) Format() error

Format 格式化配置内容 name: 执行的命令,如 go、git 等

func (*Config) Rule

func (c *Config) Rule() (*Rule, error)

type Rule

type Rule struct {
	Cmd  string
	Dir  []string `json:",omitempty"`
	Args []string `json:",omitempty"`
	Env  []string `json:",omitempty"`

	Pre  []*Command `json:",omitempty"`
	Post []*Command `json:",omitempty"`

	Trace bool `json:",omitempty"`

	Spec map[string]any `json:",omitempty"`
}

func (*Rule) BeforeExec added in v0.2.0

func (r *Rule) BeforeExec(name string) error

func (*Rule) Format added in v0.1.1

func (r *Rule) Format() error

Format 格式化当前配置

func (*Rule) Match

func (r *Rule) Match(wd string) int

func (*Rule) Merge added in v0.2.0

func (r *Rule) Merge(b *Rule)

Merge 将 b merge 到 r

func (*Rule) Run

func (r *Rule) Run(args []string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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