config

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides configuration management for the Sanity CLI.

Index

Constants

View Source
const (
	// DefaultAPIVersion is used when no version is provided.
	DefaultAPIVersion = "2024-10-01"

	// DefaultPerspective is used when no perspective is provided.
	DefaultPerspective = "published"

	// DefaultInstanceName is the name assigned during first-run setup.
	DefaultInstanceName = "default"
)

Variables

View Source
var GetConfigDir = func() (string, error) {
	configDir, err := os.UserConfigDir()
	if err != nil {
		return "", fmt.Errorf("failed to get user config directory: %w", err)
	}
	return filepath.Join(configDir, "sanity-cli"), nil
}

GetConfigDir returns the platform-specific config directory for sanity-cli.

Functions

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the full path to the config file.

func GetSchemasDir

func GetSchemasDir() (string, error)

GetSchemasDir returns the directory used to cache introspected schemas.

func RedactToken

func RedactToken(token string) string

RedactToken returns a redacted form of the token, suitable for display.

func Save

func Save(cfg *Config) error

Save writes the config to disk with secure permissions.

Types

type Config

type Config struct {
	CurrentInstance  string               `json:"current_instance,omitempty"`
	DefaultProjectID string               `json:"default_project_id,omitempty"`
	Instances        map[string]*Instance `json:"instances,omitempty"`
}

Config holds the application configuration that is persisted to disk.

func Load

func Load() (*Config, error)

Load reads the config file. Returns an empty Config if the file doesn't exist.

type Instance

type Instance struct {
	ProjectID   string `json:"project_id"`
	Dataset     string `json:"dataset"`
	Token       string `json:"token"`
	APIVersion  string `json:"api_version,omitempty"`
	UseCDN      bool   `json:"use_cdn,omitempty"`
	Perspective string `json:"perspective,omitempty"`
}

Instance represents a single Sanity environment (project + dataset + token).

func PromptForInstance

func PromptForInstance(name string) (*Instance, error)

PromptForInstance interactively prompts for instance fields.

func (*Instance) EffectiveAPIVersion

func (i *Instance) EffectiveAPIVersion() string

EffectiveAPIVersion returns the configured api_version or the default.

func (*Instance) EffectivePerspective

func (i *Instance) EffectivePerspective() string

EffectivePerspective returns the configured perspective or the default.

func (*Instance) Validate

func (i *Instance) Validate() error

Validate checks the instance for required fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL