Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config not read properly #673

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions internal/state/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func RemoveContext(cfg Config, context *Context) {
}

type rawConfig struct {
activeContext string
contexts []rawConfigContext
ActiveContext string `toml:"active_context,omitempty"`
Contexts []rawConfigContext `toml:"contexts"`
}

type rawConfigContext struct {
Expand All @@ -135,10 +135,10 @@ type rawConfigContext struct {
func (cfg *config) marshal() ([]byte, error) {
var raw rawConfig
if cfg.activeContext != nil {
raw.activeContext = cfg.activeContext.Name
raw.ActiveContext = cfg.activeContext.Name
}
for _, context := range cfg.contexts {
raw.contexts = append(raw.contexts, rawConfigContext{
raw.Contexts = append(raw.Contexts, rawConfigContext{
Name: context.Name,
Token: context.Token,
})
Expand All @@ -151,21 +151,21 @@ func (cfg *config) unmarshal(data []byte) error {
if err := toml.Unmarshal(data, &raw); err != nil {
return err
}
for _, rawContext := range raw.contexts {
for _, rawContext := range raw.Contexts {
cfg.contexts = append(cfg.contexts, &Context{
Name: rawContext.Name,
Token: rawContext.Token,
})
}
if raw.activeContext != "" {
if raw.ActiveContext != "" {
for _, c := range cfg.contexts {
if c.Name == raw.activeContext {
if c.Name == raw.ActiveContext {
cfg.activeContext = c
break
}
}
if cfg.activeContext == nil {
return fmt.Errorf("active context %s not found", raw.activeContext)
return fmt.Errorf("active context %s not found", raw.ActiveContext)
}
}
return nil
Expand Down