diff --git a/repository.go b/repository.go index 2a8ac62..70a41b4 100644 --- a/repository.go +++ b/repository.go @@ -4,6 +4,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/v8platform/errors" "github.com/v8platform/marshaler" + "strings" ) type RepositoryRightType string @@ -125,6 +126,7 @@ func (o RepositoryCreateOptions) WithRepository(repository Repository) Repositor func (ib RepositoryCreateOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } @@ -143,3 +145,25 @@ func (ib RepositoryCreateOptions) Check() error { return err.ErrorOrNil() } + +func fixExtensionIndex(values *[]string) { + + val := *values + extIdx := -1 + for i := 0; i < len(val); i++ { + if strings.Contains(val[i], "-Extension") { + extIdx = i + break + } + } + + if extIdx != -1 { + ext := val[extIdx] + + val = append(val[:extIdx], val[extIdx+1:]...) + val = append(val, ext) + + values = &val + } + +} diff --git a/repositoryCache.go b/repositoryCache.go index 2d1dbe9..29d9ac3 100644 --- a/repositoryCache.go +++ b/repositoryCache.go @@ -16,6 +16,7 @@ type RepositoryClearGlobalCacheOptions struct { func (ib RepositoryClearGlobalCacheOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } @@ -42,6 +43,7 @@ type RepositoryClearCacheOptions struct { func (ib RepositoryClearCacheOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } @@ -68,6 +70,7 @@ type RepositoryClearLocalCacheOptions struct { func (ib RepositoryClearLocalCacheOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } diff --git a/repositoryCfg.go b/repositoryCfg.go index 43596f0..a2fab40 100644 --- a/repositoryCfg.go +++ b/repositoryCfg.go @@ -33,6 +33,7 @@ type RepositoryBindCfgOptions struct { func (ib RepositoryBindCfgOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } @@ -85,6 +86,7 @@ type RepositoryUnbindCfgOptions struct { func (ib RepositoryUnbindCfgOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } @@ -127,6 +129,7 @@ type RepositoryDumpCfgOptions struct { func (ib RepositoryDumpCfgOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } @@ -205,6 +208,7 @@ type RepositoryUpdateCfgOptions struct { func (ib RepositoryUpdateCfgOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } diff --git a/repositoryService.go b/repositoryService.go index 2afca52..e088c79 100644 --- a/repositoryService.go +++ b/repositoryService.go @@ -50,6 +50,7 @@ type RepositoryReportOptions struct { func (ib RepositoryReportOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } diff --git a/repositoryUsers.go b/repositoryUsers.go index 0b9eaa2..0fbf058 100644 --- a/repositoryUsers.go +++ b/repositoryUsers.go @@ -36,6 +36,7 @@ type RepositoryAddUserOptions struct { func (o RepositoryAddUserOptions) Values() []string { v, _ := marshaler.Marshal(o) + fixExtensionIndex(&v) return v } @@ -93,6 +94,7 @@ type RepositoryCopyUsersOptions struct { func (ib RepositoryCopyUsersOptions) Values() []string { v, _ := marshaler.Marshal(ib) + fixExtensionIndex(&v) return v } diff --git a/repository_test.go b/repository_test.go index b778268..25137eb 100644 --- a/repository_test.go +++ b/repository_test.go @@ -452,3 +452,55 @@ func TestRepository_Values(t *testing.T) { }) } } + +func TestRepository_ValuesFixExtension(t *testing.T) { + type fields interface { + Values() []string + } + tests := []struct { + name string + fields fields + want []string + }{ + { + "simple", + Repository{ + Path: "./repo", + User: "admin", + Password: "pwd", + Extension: "", + }, + []string{ + "/ConfigurationRepositoryF ./repo", + "/ConfigurationRepositoryN admin", + "/ConfigurationRepositoryP pwd", + }, + }, + { + "ext", + Repository{ + Path: "./repo", + User: "admin", + Password: "pwd", + Extension: "test", + }.Report("./file"), + []string{ + "/DisableStartupDialogs", + "/DisableStartupMessages", + "/ConfigurationRepositoryF ./repo", + "/ConfigurationRepositoryN admin", + "/ConfigurationRepositoryP pwd", + "/ConfigurationRepositoryReport ./file", + "-Extension test", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + + if got := tt.fields.Values(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Values() = %v, want %v", got, tt.want) + } + }) + } +}