本文整理汇总了Golang中github.com/bitrise-io/envman/models.EnvironmentItemModel.GetKeyValuePair方法的典型用法代码示例。如果您正苦于以下问题:Golang EnvironmentItemModel.GetKeyValuePair方法的具体用法?Golang EnvironmentItemModel.GetKeyValuePair怎么用?Golang EnvironmentItemModel.GetKeyValuePair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bitrise-io/envman/models.EnvironmentItemModel
的用法示例。
在下文中一共展示了EnvironmentItemModel.GetKeyValuePair方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MergeEnvironmentWith
// MergeEnvironmentWith ...
func MergeEnvironmentWith(env *envmanModels.EnvironmentItemModel, otherEnv envmanModels.EnvironmentItemModel) error {
// merge key-value
key, _, err := env.GetKeyValuePair()
if err != nil {
return err
}
otherKey, otherValue, err := otherEnv.GetKeyValuePair()
if err != nil {
return err
}
if otherKey != key {
return errors.New("Env keys are diferent")
}
(*env)[key] = otherValue
//merge options
options, err := env.GetOptions()
if err != nil {
return err
}
otherOptions, err := otherEnv.GetOptions()
if err != nil {
return err
}
if otherOptions.Title != nil {
options.Title = pointers.NewStringPtr(*otherOptions.Title)
}
if otherOptions.Description != nil {
options.Description = pointers.NewStringPtr(*otherOptions.Description)
}
if otherOptions.Summary != nil {
options.Summary = pointers.NewStringPtr(*otherOptions.Summary)
}
if len(otherOptions.ValueOptions) > 0 {
options.ValueOptions = otherOptions.ValueOptions
}
if otherOptions.IsRequired != nil {
options.IsRequired = pointers.NewBoolPtr(*otherOptions.IsRequired)
}
if otherOptions.IsExpand != nil {
options.IsExpand = pointers.NewBoolPtr(*otherOptions.IsExpand)
}
if otherOptions.IsDontChangeValue != nil {
options.IsDontChangeValue = pointers.NewBoolPtr(*otherOptions.IsDontChangeValue)
}
if otherOptions.IsTemplate != nil {
options.IsTemplate = pointers.NewBoolPtr(*otherOptions.IsTemplate)
}
(*env)[envmanModels.OptionsKey] = options
return nil
}
示例2: countOfEnvKeyInEnvSlice
func countOfEnvKeyInEnvSlice(env models.EnvironmentItemModel, envSlice []models.EnvironmentItemModel) (cnt int, err error) {
for _, e := range envSlice {
key, _, err := env.GetKeyValuePair()
if err != nil {
return 0, err
}
k, _, err := e.GetKeyValuePair()
if err != nil {
return 0, err
}
if key == k {
cnt++
}
}
return
}
示例3: ValidateStepInputOutputModel
// ValidateStepInputOutputModel ...
func ValidateStepInputOutputModel(env envmanModels.EnvironmentItemModel) error {
key, _, err := env.GetKeyValuePair()
if err != nil {
return err
}
if key == "" {
return errors.New("Invalid environment: empty env_key")
}
options, err := env.GetOptions()
if err != nil {
return err
}
if options.Title == nil || *options.Title == "" {
return errors.New("Invalid environment: missing or empty title")
}
return nil
}
示例4: ValidateStepInputOutputModel
// ValidateStepInputOutputModel ...
func ValidateStepInputOutputModel(env envmanModels.EnvironmentItemModel, checkRequiredFields bool) error {
key, _, err := env.GetKeyValuePair()
if err != nil {
return fmt.Errorf("Invalid environment (%s), err: %s", key, err)
}
if err := env.Validate(); err != nil {
return fmt.Errorf("Invalid environment (%s), err: %s", key, err)
}
if checkRequiredFields {
options, err := env.GetOptions()
if err != nil {
return fmt.Errorf("Invalid environment (%s), err: %s", key, err)
}
if options.Title == nil || *options.Title == "" {
return fmt.Errorf("Invalid environment (%s), err: missing or empty title", key)
}
}
return nil
}
示例5: TestCommandEnvs
func TestCommandEnvs(t *testing.T) {
t.Log("commandEnvs test")
{
env1 := models.EnvironmentItemModel{
"test_key1": "test_value1",
}
require.Equal(t, nil, env1.FillMissingDefaults())
env2 := models.EnvironmentItemModel{
"test_key2": "test_value2",
}
require.Equal(t, nil, env2.FillMissingDefaults())
envs := []models.EnvironmentItemModel{env1, env2}
sessionEnvs, err := commandEnvs(envs)
require.Equal(t, nil, err)
env1Found := false
env2Found := false
for _, envString := range sessionEnvs {
comp := strings.Split(envString, "=")
key := comp[0]
value := comp[1]
envKey1, envValue1, err := env1.GetKeyValuePair()
require.Equal(t, nil, err)
envKey2, envValue2, err := env2.GetKeyValuePair()
require.Equal(t, nil, err)
if key == envKey1 && value == envValue1 {
env1Found = true
}
if key == envKey2 && value == envValue2 {
env2Found = true
}
}
require.Equal(t, true, env1Found)
require.Equal(t, true, env2Found)
}
// Test skip_if_empty
t.Log("skip_if_empty=false && value=empty => should add")
{
env1 := models.EnvironmentItemModel{
"test_key3": "",
}
require.Equal(t, nil, env1.FillMissingDefaults())
env2 := models.EnvironmentItemModel{
"test_key4": "test_value4",
}
require.Equal(t, nil, env2.FillMissingDefaults())
envs := []models.EnvironmentItemModel{env1, env2}
sessionEnvs, err := commandEnvs(envs)
require.Equal(t, nil, err)
env1Found := false
env2Found := false
for _, envString := range sessionEnvs {
comp := strings.Split(envString, "=")
key := comp[0]
value := comp[1]
envKey1, envValue1, err := env1.GetKeyValuePair()
require.Equal(t, nil, err)
envKey2, envValue2, err := env2.GetKeyValuePair()
require.Equal(t, nil, err)
if key == envKey1 && value == envValue1 {
env1Found = true
}
if key == envKey2 && value == envValue2 {
env2Found = true
}
}
require.Equal(t, true, env1Found)
require.Equal(t, true, env2Found)
}
t.Log("skip_if_empty=true && value=empty => should NOT add")
{
env1 := models.EnvironmentItemModel{
"test_key5": "",
"opts": models.EnvironmentItemOptionsModel{
SkipIfEmpty: pointers.NewBoolPtr(true),
},
}
require.Equal(t, nil, env1.FillMissingDefaults())
env2 := models.EnvironmentItemModel{
"test_key6": "test_value6",
}
require.Equal(t, nil, env2.FillMissingDefaults())
envs := []models.EnvironmentItemModel{env1, env2}
//.........这里部分代码省略.........
示例6: UpdateOrAddToEnvlist
// UpdateOrAddToEnvlist ...
func UpdateOrAddToEnvlist(oldEnvSlice []models.EnvironmentItemModel, newEnv models.EnvironmentItemModel, replace bool) ([]models.EnvironmentItemModel, error) {
newKey, _, err := newEnv.GetKeyValuePair()
if err != nil {
return []models.EnvironmentItemModel{}, err
}
var newEnvs []models.EnvironmentItemModel
exist := false
if replace {
match := 0
for _, env := range oldEnvSlice {
key, _, err := env.GetKeyValuePair()
if err != nil {
return []models.EnvironmentItemModel{}, err
}
if key == newKey {
match = match + 1
}
}
if match > 1 {
if ToolMode {
return []models.EnvironmentItemModel{}, errors.New("More then one env exist with key '" + newKey + "'")
}
msg := " More then one env exist with key '" + newKey + "' replace all/append ['replace/append'] ?"
answer, err := goinp.AskForString(msg)
if err != nil {
return []models.EnvironmentItemModel{}, err
}
switch answer {
case "replace":
break
case "append":
replace = false
break
default:
return []models.EnvironmentItemModel{}, errors.New("Failed to parse answer: '" + answer + "' use ['replace/append']!")
}
}
}
for _, env := range oldEnvSlice {
key, _, err := env.GetKeyValuePair()
if err != nil {
return []models.EnvironmentItemModel{}, err
}
if replace && key == newKey {
exist = true
newEnvs = append(newEnvs, newEnv)
} else {
newEnvs = append(newEnvs, env)
}
}
if !exist {
newEnvs = append(newEnvs, newEnv)
}
return newEnvs, nil
}