sq/cli/config/store.go

42 lines
950 B
Go
Raw Normal View History

2020-08-06 20:58:47 +03:00
package config
import (
2023-04-22 16:37:07 +03:00
"context"
2020-08-06 20:58:47 +03:00
"github.com/neilotoole/sq/libsq/core/options"
2020-08-06 20:58:47 +03:00
)
// Store saves and loads config.
type Store interface {
// Save writes config to the store.
2023-04-22 16:37:07 +03:00
Save(ctx context.Context, cfg *Config) error
2020-08-06 20:58:47 +03:00
// Load reads config from the store.
Load(ctx context.Context, optsReg *options.Registry) (*Config, error)
2020-08-06 20:58:47 +03:00
// Location returns the location of the store, typically
// a file path.
Location() string
}
// DiscardStore implements Store but its Save method is no-op
// and Load always returns a new empty Config. Useful for testing.
type DiscardStore struct{}
2020-08-06 20:58:47 +03:00
var _ Store = (*DiscardStore)(nil)
// Load returns a new empty Config.
func (DiscardStore) Load(context.Context, *options.Registry) (*Config, error) {
2020-08-06 20:58:47 +03:00
return New(), nil
}
// Save is no-op.
2023-04-22 16:37:07 +03:00
func (DiscardStore) Save(context.Context, *Config) error {
2020-08-06 20:58:47 +03:00
return nil
}
// Location returns /dev/null.
2020-08-06 20:58:47 +03:00
func (DiscardStore) Location() string {
return "/dev/null"
}