示例#1
0
文件: eval.go 项目: yonglehou/hpipe
func (this *Eval) evalEnv(stmt *ast.Stmt) (*ast.Stmt, error) {
	name := stmt.Value.(string)
	stmt.Prop["name"] = name
	env := os.Getenv(name)
	if len(env) == 0 {
		return nil, fmt.Errorf("invalid env: %s", name)
	} else {
		return ast.NewString(env), nil
	}
}
示例#2
0
func NewBuiltins() *Builtins {
	return &Builtins{builtins: map[string]*ast.Stmt{
		// Date
		"gmtdate": ast.NewDate(stdtime.Now(), "YYYYMMDD"),
		"bizdate": ast.NewDate(stdtime.Now().AddDate(0, 0, -1), "YYYYMMDD"),
		// Duration
		"year":   ast.NewDurationExt(1, 0, 0),
		"month":  ast.NewDurationExt(0, 1, 0),
		"day":    ast.NewDurationExt(0, 0, 1),
		"hour":   ast.NewDuration(stdtime.Hour),
		"minute": ast.NewDuration(stdtime.Minute),
		"second": ast.NewDuration(stdtime.Second),
		// System
		"job_report": ast.NewString("{}"),
	}}
}
示例#3
0
func TestEvalEnv(t *testing.T) {
	src := "$res=${env:HADOOP_HOME}"
	os.Setenv("HADOOP_HOME", "/hadoop_home")
	//fmt.Printf("src: %s\n", src)
	ret := getTestEvalResult(src, t)
	if ret == nil {
		return
	}
	res := ret[0]
	check := ast.NewLeftID("res", ast.NewString("/hadoop_home"))
	if !res.Equals(check) {
		t.Error(fmt.Errorf("%v=%v", res.Value, check.Value))
		return
	}
	//fmt.Printf("res: %v\n", res)
}
示例#4
0
func (this *Builtins) SetJobReport(status string) {
	this.builtins["job_report"] = ast.NewString(status)
}