當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Scope.Set方法代碼示例

本文整理匯總了Golang中github.com/danwakefield/gosh/variables.Scope.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Scope.Set方法的具體用法?Golang Scope.Set怎麽用?Golang Scope.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/danwakefield/gosh/variables.Scope的用法示例。


在下文中一共展示了Scope.Set方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Sub

func (s SubVariable) Sub(scp *variables.Scope) (returnString string) {
	logex.Debug("Substituting variable")
	defer func() {
		logex.Debugf("Returned '%s'", returnString)
	}()
	v := scp.Get(s.VarName)

	switch s.SubType {
	case VarSubNormal:
		return v.Val
	case VarSubLength:
		// For the values ${#*} and ${#@}
		// the number of positional parameters is returned
		// We need to perform IFS splitting to figure this out
		return strconv.Itoa(len(v.Val))
	}

	varExists := v.Set == true
	// CheckNull means that an empty string is treated as unset
	if s.CheckNull {
		varExists = varExists && v.Val != ""
	}

	switch s.SubType {
	case VarSubAssign:
		if varExists {
			return v.Val
		}
		scp.Set(s.VarName, s.SubVal)
		return s.SubVal
	case VarSubMinus:
		if varExists {
			return v.Val
		}
		return s.SubVal
	case VarSubPlus:
		if varExists {
			return ""
		}
		return s.SubVal
	case VarSubQuestion:
		if varExists {
			return v.Val
		}
		if s.SubVal != "" {
			ExitShellWithMessage(T.ExitFailure, s.SubVal)
		}
		ExitShellWithMessage(T.ExitFailure, s.VarName+": Parameter not set")
	case VarSubTrimRight, VarSubTrimRightMax, VarSubTrimLeft, VarSubTrimLeftMax:
		ExitShellWithMessage(T.ExitFailure, "Trim operations not implemented")
	}

	logex.Fatal("SubVariable.Sub unreached")
	return ""
}
開發者ID:danwakefield,項目名稱:gosh,代碼行數:55,代碼來源:substitutions.go

示例2: LocalCmd

func LocalCmd(scp *variables.Scope, ioc *T.IOContainer, args []string) T.ExitStatus {
	// Local should also do assignments, split args on equal sign? already
	// expanded
	for _, a := range args {
		tmp := scp.Get(a)
		if tmp.Set {
			scp.Set(a, tmp.Val, variables.LocalScope)
		} else {
			scp.Set(a, "", variables.LocalScope)
		}
	}
	return T.ExitSuccess
}
開發者ID:danwakefield,項目名稱:gosh,代碼行數:13,代碼來源:local.go

示例3: Eval

func (n NodeFor) Eval(scp *variables.Scope, ioc *T.IOContainer) T.ExitStatus {
	returnExit := T.ExitSuccess

	expandedArgs := make([]string, len(n.Args))
	for i, arg := range n.Args {
		// This will need to be changed when IFS splitting is coded.
		// Append each split as a seperate item
		expandedArgs[i] = arg.Expand(scp)
	}

	for _, arg := range expandedArgs {
		scp.Set(n.LoopVar, arg)
		returnExit = n.Body.Eval(scp, ioc)
	}

	return returnExit
}
開發者ID:danwakefield,項目名稱:gosh,代碼行數:17,代碼來源:nodes.go


注:本文中的github.com/danwakefield/gosh/variables.Scope.Set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。