From 62920322659a443441cf3a9e4c1808bfee79c3e1 Mon Sep 17 00:00:00 2001 From: pauhull <22707808+pauhull@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:25:38 +0100 Subject: [PATCH] remove Marshal() from config.Config --- internal/state/config/config.go | 52 ++++++++++++------------- internal/state/config/zz_config_mock.go | 15 ------- 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/internal/state/config/config.go b/internal/state/config/config.go index f204aa5f..ae71dbee 100644 --- a/internal/state/config/config.go +++ b/internal/state/config/config.go @@ -12,7 +12,6 @@ import ( type Config interface { Write() error - Marshal() ([]byte, error) ActiveContext() *Context SetActiveContext(*Context) @@ -62,7 +61,7 @@ func ReadConfig(path string) (Config, error) { } func (cfg *config) Write() error { - data, err := cfg.Marshal() + data, err := cfg.marshal() if err != nil { return err } @@ -75,31 +74,6 @@ func (cfg *config) Write() error { return nil } -type rawConfig struct { - activeContext string - contexts []rawConfigContext -} - -type rawConfigContext struct { - Name string `toml:"name"` - Token string `toml:"token"` -} - -func (cfg *config) Marshal() ([]byte, error) { - - var raw rawConfig - if cfg.activeContext != nil { - raw.activeContext = cfg.activeContext.Name - } - for _, context := range cfg.contexts { - raw.contexts = append(raw.contexts, rawConfigContext{ - Name: context.Name, - Token: context.Token, - }) - } - return toml.Marshal(raw) -} - func (cfg *config) ActiveContext() *Context { return cfg.activeContext } @@ -153,6 +127,30 @@ func (cfg *config) RemoveContext(context *Context) { } } +type rawConfig struct { + activeContext string + contexts []rawConfigContext +} + +type rawConfigContext struct { + Name string `toml:"name"` + Token string `toml:"token"` +} + +func (cfg *config) marshal() ([]byte, error) { + var raw rawConfig + if cfg.activeContext != nil { + raw.activeContext = cfg.activeContext.Name + } + for _, context := range cfg.contexts { + raw.contexts = append(raw.contexts, rawConfigContext{ + Name: context.Name, + Token: context.Token, + }) + } + return toml.Marshal(raw) +} + func (cfg *config) unmarshal(data []byte) error { var raw rawConfig if err := toml.Unmarshal(data, &raw); err != nil { diff --git a/internal/state/config/zz_config_mock.go b/internal/state/config/zz_config_mock.go index f662c024..b74faab2 100644 --- a/internal/state/config/zz_config_mock.go +++ b/internal/state/config/zz_config_mock.go @@ -103,21 +103,6 @@ func (mr *MockConfigMockRecorder) Endpoint() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Endpoint", reflect.TypeOf((*MockConfig)(nil).Endpoint)) } -// Marshal mocks base method. -func (m *MockConfig) Marshal() ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Marshal") - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Marshal indicates an expected call of Marshal. -func (mr *MockConfigMockRecorder) Marshal() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Marshal", reflect.TypeOf((*MockConfig)(nil).Marshal)) -} - // RemoveContext mocks base method. func (m *MockConfig) RemoveContext(arg0 *Context) { m.ctrl.T.Helper()